Exemple #1
0
        protected override void Setup()
        {
            base.Setup();

            /*
             * Stub the interface dependencies, don't need to use the actual objects, but force of habit
             */
            StubCustomerService.Stub(s => s.GetByIdAsync(1)).Return(Task.FromResult(ActualCustomers.FirstOrDefault()));
            StubAutoMapper.Stub(m => m.Map <Customer, CustomerDto>(ActualCustomers.FirstOrDefault())).Return(ExpectedCustomerDto);

            ConfigureApi(HttpMethod.Get, "http://localhost/api/customers/1");

            ExpectedJson = JsonConvert.SerializeObject(ExpectedCustomerDto);
        }
        protected override void Setup()
        {
            base.Setup();

            /*
             * Stub the interface dependencies, don't need to use the actual objects, but force of habit
             */
            //StubCustomerService.Stub(s => s.AddAsync(NewCustomer)).Return(Task.FromResult(ExpectedNewCustomer));
            StubCustomerService.Stub(s => s.AddCustomerAsync(NewCustomer)).Return(Task.FromResult(ExpectedNewCustomer));
            StubAutoMapper.Stub(m => m.Map <CustomerDto, Customer>(NewCustomerDto)).Return(NewCustomer);

            ConfigureApi(HttpMethod.Post, "http://localhost/api/customers/");

            //Create a new user, need to swap this to a Mock Object
            CustomerControllerApi.User = new ClaimsPrincipal(new GenericPrincipal(new GenericIdentity("user"), null));
        }
        protected override void Setup()
        {
            base.Setup();

            /*
             * Stub the interface dependencies, don't need to use the actual objects, but force of habit
             */
            StubCustomerService.Stub(s => s.GetAllAsync()).Return(Task.FromResult(ActualCustomers));
            StubAutoMapper.Stub(m => m.Map <IEnumerable <Customer>, IEnumerable <CustomerDto> >(ActualCustomers)).Return(ExpectedCustomersDto);

            /*
             * Its important to set the Request and configuration on the Controller otherwise it will fail, with exceptions,
             * ArgumentNull or InvalidOperation exceptions
             */

            //CustomerControllerApi = new CustomersController(StubCustomerService, StubAddressService, StubAutoMapper);
            CustomerControllerApi         = new CustomersController(StubCustomerService, StubAutoMapper);
            CustomerControllerApi.Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/api/customers");
            //The line below was needed in WebApi RC as null config causes an issue
            CustomerControllerApi.Configuration = new System.Web.Http.HttpConfiguration(new System.Web.Http.HttpRouteCollection());

            ExpectedJson = JsonConvert.SerializeObject(ExpectedCustomersDto);
        }
Exemple #4
0
 public void GetByIdAsync_ItShouldCallTheAutoMapperEngine()
 {
     ArrangeAndAct();
     StubAutoMapper.AssertWasCalled(m => m.Map <Customer, CustomerDto>(ActualCustomers.FirstOrDefault()));
 }
 public void CreateAsync_ItShouldCallTheAutoMapperEngine()
 {
     ArrangeAndAct();
     StubAutoMapper.AssertWasCalled(m => m.Map <CustomerDto, Customer>(NewCustomerDto));
 }
 public void GetAllAsync_ItShouldCallTheAutoMapperEngine()
 {
     ArrangeAndAct();
     StubAutoMapper.AssertWasCalled(m => m.Map(ActualCustomers, ExpectedCustomersDto));
 }