Example #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(-99)).Return(Task.FromResult(new Customer {
            }));
            StubCustomerService.Stub(s => s.DeleteAsync(ActualCustomers.FirstOrDefault())).Return(Task.FromResult(ActualCustomers.FirstOrDefault()));

            ConfigureApi(HttpMethod.Delete, "http://localhost/api/customers/-99");
        }
Example #2
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);
        }
Example #3
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(-99)).Return(Task.FromResult(new Customer {
            }));
            //StubAutoMapper.Stub(m => m.Map<Customer, CustomerDto>(ActualCustomers.FirstOrDefault())).Return(ExpectedCustomerDto);

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

            ExpectedJson = "{\"Message\":\"Invalid Customer Id\"}";
        }
        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);
        }
Example #6
0
 public void GetByIdAsync_ItShouldCallTheCustomerService()
 {
     ArrangeAndAct();
     StubCustomerService.AssertWasCalled(s => s.GetByIdAsync(Arg <int> .Is.Anything));
 }
 public void CreateAsync_ItShouldCallTheCustomerService()
 {
     ArrangeAndAct();
     //StubCustomerService.AssertWasCalled(s => s.AddAsync(NewCustomer));
     StubCustomerService.AssertWasCalled(s => s.AddCustomerAsync(NewCustomer));
 }
Example #8
0
 public void DeleteByIdAsyncNotFound_ItShouldNotCallTheCustomerService_DeleteMethod()
 {
     ArrangeAndAct();
     StubCustomerService.AssertWasNotCalled(s => s.DeleteAsync(Arg <Customer> .Is.Anything));
 }
Example #9
0
 public void DeleteByIdAsyncNotFound_ItShouldCallTheCustomerService_GetByIdMethod()
 {
     ArrangeAndAct();
     StubCustomerService.AssertWasCalled(s => s.GetByIdAsync(Arg <int> .Is.Anything));
 }
 public void GetAllAsync_ItShouldCallTheCustomerService()
 {
     ArrangeAndAct();
     StubCustomerService.AssertWasCalled(s => s.GetAllAsync());
 }