示例#1
0
        public void Test_Create_Sale()
        {
            var fakeContext = new FakeContext("Create_Sale");

            fakeContext.FillWith <Sale>();

            using (var context = new MainContext(fakeContext.FakeOptions, fakeContext.FakeConfiguration().Object))
            {
                var fakeSale = new Sale();
                fakeSale.ProductId = 1;
                fakeSale.Total     = 1826.40M;
                fakeSale.Quantity  = 100;
                fakeSale.CreatedAt = new DateTime(2020, 02, 22);
                fakeSale.UpdatedAt = new DateTime(2020, 08, 15);

                var repository = new SaleRepository(context);
                repository.Create(fakeSale);
                var createdSale = repository.GetById(6);

                Assert.IsType <Sale>(createdSale);
                Assert.Equal(6, repository.GetAll().Count());
                Assert.NotEqual(0, createdSale.Id);
                Assert.Equal(1826.40M, createdSale.Total);
                Assert.Equal(100, createdSale.Quantity);
                Assert.Equal(new DateTime(2020, 02, 22), createdSale.CreatedAt);
                Assert.Equal(new DateTime(2020, 08, 15), createdSale.UpdatedAt);
                Assert.Equal(6, createdSale.Id);
            }
        }
示例#2
0
 public void Create(SaleDTO dto)
 {
     repository.Create(mapper.Map <Sale>(dto));
 }