Hi,
Actually I have several project as follows:
- Data : Business object
- DataAccess: Access to database (using EF)
- Core : Core Business Logic
- Contract : Datacontract and Operationcontract for WCF Service
- Service : Service Implementation
Here are all my implementation example code
namespace Data { public class Employee { public string Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } } }
namespace DataAccess { public class EmployeeDBContext: DbContext { public EmployeeDBContext() : base("EmployeeDBContext") { } public DbSet<Employee> Employee { get; set; } } }
namespace Core { public class EmployeeRepository : IEmployeeRepository { private EmployeeDBContext employeeDBContext; public EmployeeRepository() { employeeDBContext = new EmployeeDBContext(); } public Employee GetEmployeeById (string id) { bool exist = employeeDBContext.Database.Exists(); Employee emp = employeeDBContext.Employee .Where(i => i.Id == id) .SingleOrDefault(); return emp; } } }
namespace Contract.Data { [DataContract(Name="EmployeeDTO", Namespace= Namespaces.V1)] public class EmployeeDTO { [DataMember(IsRequired=true,Order = 1)] public string Id { get; set; } [DataMember(IsRequired = true, Order = 2)] public string FirstName { get; set; } [DataMember(IsRequired=true,Order = 3)] public string LastName { get; set; } [DataMember(IsRequired = true, Order = 4)] public int Age { get; set; } } }
namespace Contract.Operation { [ServiceContract(Namespace = Namespaces.V1)] public interface IEmployee { [OperationContract] EmployeeDTO GetEmployee(string id); } }
namespace Service { [ServiceBehavior(Namespace = Namespaces.V1)] public class EmployeeImpl : IEmployee { private IEmployeeRepository employeeRepository; public EmployeeImpl(IEmployeeRepository employeeRepository) { this.employeeRepository = employeeRepository; } public EmployeeDTO GetEmployee(string id) { Employee emp = employeeRepository.GetEmployeeById(id); EmployeeDTO eDto = Mapper.Map<Employee, EmployeeDTO>(emp); return eDto; } } }
Now I am trying to create unit test to test my WCF Service
which is it has dependency to database. GetEmployee is the method that I
want to test. Because I am very new in unit testing and mocking, can
anyone help me to give example using unit testing and mocking for
EmployeeImpl below? For example given Id "1" then it should be return
LastName "Putra". Many thanks
namespace Service.UnitTest { [TestFixture] public class EmployeeImplTests { [Test] public void If_id_is_1_the_employee_name_shall_be_putra { //Can anyone please help me, what should I write here to mocking the webservice using Moq } } }
Regards
--
--
Post: moq...@googlegroups.com
Unsubscribe: moqdisc-u...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Moq Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moqdisc+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.