コード例 #1
0
        public void Can_add_new_cost_type_with_new_costs()
        {
            var costType = new CostType("new cost type");
            ICostTypeRepository costTypeRepository = new CostTypeRepository();
            costTypeRepository.Add(costType);

            var cost1 = new Cost(1000.11);
            var cost2 = new Cost(1500.11);
            ICostRepository costRepository = new CostRepository();
            costRepository.Add(cost1);
            costRepository.Add(cost2);

            IList<Cost> possibleCosts = new List<Cost>();
            possibleCosts.Add(cost1);
            possibleCosts.Add(cost2);
            costType.PossibleCosts = possibleCosts;

            costTypeRepository.Update(costType);

            // use session to try to load the cost type
            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<CostType>(costType.CostTypeId);
                // Test that the costType was successfully inserted
                Assert.IsNotNull(fromDb);
                Assert.AreNotSame(costType, fromDb);
                Assert.AreEqual(costType.CostName, fromDb.CostName);
                Assert.AreEqual(possibleCosts.Count, fromDb.PossibleCosts.Count);
            }

            costTypeRepository.Remove(costType);
            costRepository.Remove(cost1);
            costRepository.Remove(cost2);
        }
コード例 #2
0
        public void Can_update_existing_costType()
        {
            var costType = _costTypes[1];
            costType.CostName = "test cost name update";
            ICostTypeRepository repository = new CostTypeRepository();
            repository.Update(costType);

            // use session to try to load the costType
            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<CostType>(costType.CostTypeId);
                Assert.AreEqual(costType.CostName, fromDb.CostName);
            }
        }