コード例 #1
0
 public void Can_GetId()
 {
     Guid id = Guid.NewGuid();
     HenHouse house = new HenHouse();
     houseServiceMock.Setup(s => s.Get(id)).Returns(house);
     Assert.Equal(house, controller.GetById(id));
 }
コード例 #2
0
        public void Can_PostHouse()
        {
            var house = new HenHouse
            {
                Active = false,
                Name = "a",
                PurchaseCost = 1,
                Depreciation = 1,
                YearUsage = 1
            };

            controller.Post(house);
        }
コード例 #3
0
        public void Can_SaveNewConsumable()
        {
            var consumable = new Consumable
                {
                    Id = Guid.NewGuid(),
                    Name = "Zat 1",
                    Type = (byte) ConsumableType.Feed,
                    Unit = "liter",
                    UnitPrice = 10000
                };

            var house = new HenHouse
                {
                    Id = Guid.NewGuid(),
                    Name = "House 1",
                    Depreciation = 100,
                    Active = true,
                    PurchaseCost = 100000
                };

            using (var conn = factory.OpenDbConnection())
            {
                conn.InsertParam(house);
                conn.InsertParam(consumable);
            }

            var usage = new Models.ConsumableUsage
                {
                    Total = 10000,
                    Date = DateTime.Today,
                    Details = new List<ConsumableUsageDetail>
                        {
                            new ConsumableUsageDetail
                                {
                                    ConsumableId = consumable.Id,
                                    Count = 10,
                                    HouseId = house.Id,
                                    SubTotal = 10000,
                                    UnitPrice = 100000
                                }
                        }
                };

            service.Save(usage);

            using (var conn = factory.OpenDbConnection())
            {
                var usageData = conn.FirstOrDefault<Models.Data.ConsumableUsage>(c => c.Date == usage.Date);
                var details = conn.Where<Models.Data.ConsumableUsageDetail>(new {UsageId = usageData.Id});
                Compare(usageData, details, usage);
            }
        }
コード例 #4
0
        public void Can_PutHouse()
        {
            Guid id = Guid.NewGuid();
            var house = new HenHouse
            {
                Id = id,
                Active = false,
                Name = "a",
                PurchaseCost = 1,
                Depreciation = 1,
                YearUsage = 1
            };

            controller.Put(id, house);
        }
コード例 #5
0
        public void Put_ReturnsInternalServer_IfSavingFailed()
        {
            Guid id = Guid.NewGuid();
            var house = new HenHouse
            {
                Id=id,
                Active = false,
                Name = "a",
                PurchaseCost = 1,
                Depreciation = 1,
                YearUsage = 1
            };

            houseServiceMock.Setup(c => c.Save(house)).Throws(new Exception("Whatever"));
            var msg = controller.Put(id, house);
            Assert.Equal(HttpStatusCode.InternalServerError, msg.StatusCode);
        }
コード例 #6
0
        public void Put_GetBadRequest_IfYearUsageIsZero()
        {
            Guid id = Guid.NewGuid();

            var house = new HenHouse
            {
                Id = id,
                Active = false,
                Name = "a",
                PurchaseCost = 1,
                Depreciation = 1
            };

            var msg = controller.Put(id, house);
            Assert.Equal(HttpStatusCode.BadRequest, msg.StatusCode);
            AssertPropertyError(msg, "YearUsage");
        }
コード例 #7
0
        public void Post_GetBadRequest_IfPurchaseCostIsZero()
        {
            var house = new HenHouse
            {
                Active = false,
                Depreciation = 12,
                Name="a",
                YearUsage = 1
            };

            var msg = controller.Post(house);
            Assert.Equal(HttpStatusCode.BadRequest, msg.StatusCode);
            AssertPropertyError(msg, "PurchaseCost");
        }