public async Task CreateCustomerAsync_CanCreateCustomer_ShouldCreateExpectedCustomer()
        {
            //Arrange
            var preferenceId = Guid.Parse("ef7f299f-92d7-459f-896e-078ed53ef99c");
            var request      = new CreateOrEditCustomerRequest()
            {
                Email         = "*****@*****.**",
                FirstName     = "Иван",
                LastName      = "Петров",
                PreferenceIds = new List <Guid>()
                {
                    preferenceId
                }
            };

            //Act
            var result = await _customersController.CreateCustomerAsync(request);

            var actionResult = result.Result as CreatedAtActionResult;
            var id           = (Guid)actionResult.Value;

            //Assert
            var actual = await _customerRepository.GetByIdAsync(id);

            actual.Email.Should().Be(request.Email);
            actual.FirstName.Should().Be(request.FirstName);
            actual.LastName.Should().Be(request.LastName);

            // actual.Preferences.Should()
            //     .ContainSingle()
            //     .And
            //     .Contain(x => x.PreferenceId == preferenceId);
        }
Ejemplo n.º 2
0
        public async Task Delete_customer_success()
        {
            var newCustomer        = GetTestCustomer();
            var context            = new CustomerContext(_dbFixture.DbOptions);
            var customerController = new CustomersController(context);
            var createResult       = (CreatedAtActionResult)await customerController.CreateCustomerAsync(newCustomer);

            var id = int.Parse(createResult.RouteValues["id"].ToString());

            var deleteResult = await customerController.DeleteCustomerByIdAsync(id);

            var actionResult = await customerController.GetCustomerByIdAsync(id);

            Assert.Null(actionResult.Value);
        }
Ejemplo n.º 3
0
        public async Task Update_customer_success()
        {
            var newCustomer        = GetTestCustomer();
            var context            = new CustomerContext(_dbFixture.DbOptions);
            var customerController = new CustomersController(context);
            var createResult       = (CreatedAtActionResult)await customerController.CreateCustomerAsync(newCustomer);

            var id = int.Parse(createResult.RouteValues["id"].ToString());

            newCustomer.LastName = "Persons";
            var updateResult = await customerController.UpdateCustomerAsync(id, newCustomer);

            var actionResult = await customerController.GetCustomerByIdAsync(id);

            Assert.Equal(newCustomer.LastName, actionResult.Value.LastName);
        }
Ejemplo n.º 4
0
        public async Task Create_customer_success()
        {
            var newCustomer = GetTestCustomer();

            var context = new CustomerContext(_dbFixture.DbOptions);

            var customerController = new CustomersController(context);

            var actionResult = (CreatedAtActionResult)await customerController.CreateCustomerAsync(newCustomer);

            var id = int.Parse(actionResult.RouteValues["id"].ToString());

            var customer = await customerController.GetCustomerByIdAsync(id);

            Assert.Equal(newCustomer.FirstName, customer.Value.FirstName);
            Assert.Equal(newCustomer.LastName, customer.Value.LastName);
            Assert.Equal(newCustomer.DateOfBirth, customer.Value.DateOfBirth);
        }