コード例 #1
0
ファイル: SalesControllerTests.cs プロジェクト: njmube/public
        public void PostCallsTheLogicToAddTheNewSale()
        {
            var model = new SaleModel();

              sut.Create(model);

              logic.Verify(it => it.AddSale(model));
        }
コード例 #2
0
ファイル: SalesController.cs プロジェクト: njmube/public
        public ActionResult Create()
        {
            var model = new SaleModel
              {
            Date = DateTime.Today.ToString(Constants.DATE_FORMAT),
            Items = new List<SaleItemModel> { new SaleItemModel() }
              };

              return View(model);
        }
コード例 #3
0
ファイル: SalesController.cs プロジェクト: njmube/public
        public ActionResult Create(SaleModel model)
        {
            logic.AddSale(model);

              return RedirectToAction("Create");
        }
コード例 #4
0
ファイル: BusinessLogicTests.cs プロジェクト: njmube/public
            public void ThrowsIfThereAreMissingProducts()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc", SalePrice = 12.34m});
                stocks.Add(new Stock {Id = 1, ProductId = 1, Quantity = 22.35m});

                var model = new SaleModel
                {
                  CompanyName = "Microsoft",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new SaleItemModel {ProductName = "abc", Quantity = "1.23", Price = "4"},
                new SaleItemModel {ProductName = "def", Quantity = "5.67", Price = "8"},
                  },
                };

                Action Act = () => sut.AddSale(model);
                Act.ShouldThrow<Exception>().WithMessage("Unknown product [def]");
            }
コード例 #5
0
ファイル: BusinessLogicTests.cs プロジェクト: njmube/public
            public void UpdatesTheStock()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc", SalePrice = 5.50m});
                stocks.Add(new Stock {Id = 1, ProductId = 1, Name = "abc", Quantity = 22.35m});
                var model = new SaleModel
                {
                  CompanyName = "Microsoft",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new SaleItemModel {ProductName = "abc", Quantity = "1.23", Price = "6"},
                  },
                };

                sut.AddSale(model);

                stocks.Should().HaveCount(1);
                stocks[0].Quantity.Should().Be(21.12m);
            }
コード例 #6
0
ファイル: BusinessLogicTests.cs プロジェクト: njmube/public
            public void DoesNotCommitTheTransactionIfThereAreMissingProducts()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc", SalePrice = 12.34m});
                stocks.Add(new Stock {Id = 1, ProductId = 1, Quantity = 22.35m});

                var model = new SaleModel
                {
                  CompanyName = "Microsoft",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new SaleItemModel {ProductName = "abc", Quantity = "1.23", Price = "4"},
                new SaleItemModel {ProductName = "def", Quantity = "5.67", Price = "8"},
                  },
                };

                try
                {
                  sut.AddSale(model);
                }
                catch (Exception)
                {
                  // ignore
                }

                transaction.Verify(it => it.Commit(), Times.Never());
            }
コード例 #7
0
ファイル: BusinessLogicTests.cs プロジェクト: njmube/public
            public void DoesNotAddTheRootObjectIfAllItemsAreInvalid()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                var model = new SaleModel
                {
                  CompanyName = "Microsoft",
                  Date = "1/1/2000",
                  Items = new[]
                  {
                new SaleItemModel {ProductName = null, Quantity = "1", Price = "1"},
                new SaleItemModel {ProductName = "b", Quantity = "", Price = "2"},
                new SaleItemModel {ProductName = "c", Quantity = "3", Price = ""},
                  },
                };

                sut.AddSale(model);

                sales.Should().BeEmpty();
            }
コード例 #8
0
ファイル: BusinessLogicTests.cs プロジェクト: njmube/public
            public void CommitsTheTransaction()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc", SalePrice = 5.50m});
                stocks.Add(new Stock {Id = 1, ProductId = 1, Name = "abc", Quantity = 22.35m});
                var model = new SaleModel
                {
                  CompanyName = "Microsoft",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new SaleItemModel {ProductName = "abc", Quantity = "1.23", Price = "6"},
                  },
                };

                sut.AddSale(model);

                transaction.Verify(it => it.Commit());
            }
コード例 #9
0
ファイル: BusinessLogicTests.cs プロジェクト: njmube/public
            public void AddsTheCorrectValuesToTheRepository()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc"});
                products.Add(new Product {Id = 2, Name = "def"});
                stocks.Add(new Stock {Id = 1, ProductId = 1, Quantity = 22.35m});
                stocks.Add(new Stock {Id = 2, ProductId = 2, Quantity = 10.05m});
                var model = new SaleModel
                {
                  CompanyName = "Microsoft",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new SaleItemModel {ProductName = "abc", Quantity = "1.23", Price = "4"},
                new SaleItemModel {ProductName = "def", Quantity = "5.67", Price = "8"},
                  },
                };

                sut.AddSale(model);

                sales.Should().HaveCount(1);
                var sale = sales[0];
                sale.ShouldBeEquivalentTo(new Sale
                {
                  Id = 1,
                  Company = new Company {Id = 1, Name = "Microsoft"},
                  Date = new DateTime(2000, 2, 3),
                  Items = new Collection<SaleItem>
                  {
                new SaleItem {Product = new Product {Id = 1, Name = "abc"}, ProductId = 1, Quantity = 1.23m, Price = 4.00m,},
                new SaleItem {Product = new Product {Id = 2, Name = "def"}, ProductId = 2, Quantity = 5.67m, Price = 8.00m,}
                  }
                });
                repository.Verify(it => it.SaveChanges());
            }
コード例 #10
0
ファイル: BusinessLogicTests.cs プロジェクト: njmube/public
            public void AddsTheCompanyIfNeeded()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc", SalePrice = 1.23m});
                products.Add(new Product {Id = 2, Name = "def", SalePrice = 1.23m});
                stocks.Add(new Stock {Id = 1, ProductId = 1, Quantity = 22.35m});
                stocks.Add(new Stock {Id = 2, ProductId = 2, Quantity = 10.05m});
                var model = new SaleModel
                {
                  CompanyName = "Google",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new SaleItemModel {ProductName = "abc", Quantity = "1.23", Price = "4"},
                new SaleItemModel {ProductName = "def", Quantity = "5.67", Price = "8"},
                  },
                };

                sut.AddSale(model);

                companies.Should().HaveCount(2);
                companies[1].Name.Should().Be("Google");
            }