コード例 #1
0
        public async Task AddCustomerAsync_WithValidCustomerModel_AddsNewRecordIntoDb()
        {
            // Arrange
            using (var context = await RepositoryTestHelper.GetInMemoryCustomerDbContext("AddTest1Db"))
            {
                var customerRepository = new CustomerRepository(context);
                var newCustomer        = new CustomerModel
                {
                    FirstName   = "Alan",
                    LastName    = "Turing",
                    DateOfBirth = new DateTime(1912, 6, 23)
                };

                var expectedResult = RepositoryTestHelper.GetMockCustomerData()
                                     .ToList();
                expectedResult.Add(new CustomerEntity
                {
                    Id          = 5,
                    FirstName   = newCustomer.FirstName,
                    LastName    = newCustomer.LastName,
                    DateOfBirth = newCustomer.DateOfBirth
                }
                                   );

                // Act
                await customerRepository.AddCustomerAsync(newCustomer);

                var result = await customerRepository.GetAllCustomersAsync();

                // Assert
                result.Should().BeEquivalentTo(expectedResult);
            }
        }
コード例 #2
0
    /// <summary>
    /// Test Unit to Save Costumer
    /// </summary>
    /// <returns></returns>
    public async Task <int> SaveModelsAsyncTest()
    {
        try
        {
            CustomerModel model = new CustomerModel(
                1,
                "Moises",
                "92972566",
                "Luanda",
                "*****@*****.**",
                DateTime.Now,
                "computador",
                DateTime.Now,
                "Root",
                1);
            int i = await customerRepository.AddCustomerAsync(model);

            if (i != 0)
            {
                return(i);
            }
            return(0);
        }
        catch
        {
            return(0);
        }
    }
コード例 #3
0
        public async Task <int> AddCustomer(CustomerModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Name))
            {
                return(0);
            }
            try
            {
                int i = await customerRepository.AddCustomerAsync(model);

                if (i != 0)
                {
                    return(i);
                }
                return(0);
            }
            catch
            {
                Logger.AddToLog("Add Costumer Controller", "Mysql, error on Add Model to Repository");
                Logger.WriteLog();
                return(0);
            }
        }
コード例 #4
0
ファイル: Service1.svc.cs プロジェクト: TaskForce247/NewRepo5
 public async Task AddCustomerAsync(Cor.Models.Customer customer)
 {
     await customerRepository.AddCustomerAsync(customer);
 }