Exemplo n.º 1
0
        public void AddWhenValidObjectPassedReturnsCreatedResponse()
        {
            var    fixture         = new Fixture();
            string customerName    = fixture.Create <string>();
            var    createdResponse = controller.AddCustomer(customerName);

            Assert.IsType <CreatedAtActionResult>(createdResponse);
        }
Exemplo n.º 2
0
        public async Task FailedToSaveNewCustomers_AddCustomer_ReturnBadRequest()
        {
            var customerModel = new CustomerModel();

            var response = await _customerController.AddCustomer(customerModel);

            Assert.IsType <ActionResult <CustomerModel> >(response);
            Assert.IsType <BadRequestResult>(response.Result);
            _customerService.Verify(c => c.Add(It.IsAny <Customer>()));
        }
Exemplo n.º 3
0
        public async Task AddCustomer_ValidParams_ReturnsCreated()
        {
            var customer = new CustomerDto()
            {
                Name = "Elon Musk", Email = "*****@*****.**"
            };
            var customerWithId = new CustomerDto()
            {
                Id = 1, Name = "Elon Musk", Email = "*****@*****.**"
            };

            var mockRepository = Substitute.For <ICustomersRepository>();

            mockRepository.AddCustomerAsync(customer).Returns(customerWithId);

            var controller = new CustomersController(mockRepository);

            var response = await controller.AddCustomer(customer);

            response.Should().NotBeNull();
            response.Result.Should().BeOfType <CreatedAtRouteResult>()
            .Which.StatusCode.Should().Be((int)HttpStatusCode.Created);

            var ok = response.Result as CreatedAtRouteResult;

            ok.RouteValues["Id"].Should().Be(customerWithId.Id);
            ok.Value.Should().BeOfType <CustomerDto>();
            ok.Value.Should().BeEquivalentTo(customerWithId,
                                             opt => opt.IgnoringCyclicReferences().Excluding(c => c.Orders));

            await mockRepository.Received().AddCustomerAsync(customer);
        }
        public void AddCustomerTest()
        {
            var customer = new Customers.API.Models.Customer
            {
                Id          = new Guid(),
                FirstName   = "Steve",
                LastName    = "Smith",
                DateOfBirth = new DateTimeOffset(1990, 1, 1, 0, 0, 0, new TimeSpan(-2, 0, 0))
            };
            var createdAtRouteResult = _controller.AddCustomer(customer).Result as CreatedAtRouteResult;

            Assert.Equal(201, createdAtRouteResult?.StatusCode);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> AddCustomer(Customer customer)
        {
            IServiceProvider provider = TestServiceProvider.CreateProvider(_setup);

            using (IServiceScope scope = provider.CreateScope())
            {
                CustomersController controller = scope.ServiceProvider.GetRequiredService <CustomersController>();
                IActionResult       result     = await controller.AddCustomer(customer, scope.ServiceProvider.GetRequiredService <AddCustomerCommand>());

                await SnapshotRepository(scope.ServiceProvider);

                return(result);
            }
        }
Exemplo n.º 6
0
        public void Test_AddCustomer()
        {
            // Arrange
            var customerModel = mapper.Map <CustomerModel>(mockCustomer);
            var customerVM    = mapper.Map <CustomerViewModel>(customerModel);

            // Act
            var result        = controller.AddCustomer(customerVM);
            var contentResult = result as OkNegotiatedContentResult <CustomerViewModel>;
            var content       = contentResult.Content;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.AreEqual(mockCustomer.Guid, content.Guid);
            Assert.AreEqual(mockCustomer.Number, content.Number);
            Assert.AreEqual(mockCustomer.Address.City, content.Address.City);
        }
Exemplo n.º 7
0
        public async Task AddCustomer_InvalidParams_ReturnsBadRequest()
        {
            var customer = new CustomerDto()
            {
                Name = "Elon Musk", Email = "elon.musk.mars.com"
            };

            var mockRepository = Substitute.For <ICustomersRepository>();

            mockRepository.AddCustomerAsync(customer).Throws <ValidationException>();

            var controller = new CustomersController(mockRepository);

            Func <Task <ActionResult <CustomerDto> > > response = async() => await controller.AddCustomer(customer);

            await response.Should().ThrowAsync <ValidationException>();

            await mockRepository.Received().AddCustomerAsync(customer);
        }
 // <snippet id="CustomersSimpleViewPresenter_CustomersIDU">
 public void OnCustomerInserted(Customer customer)
 {
     _controller.AddCustomer(customer);
 }