public void TestThatUpdateUpdatesFoodItem() { var primaryFoodGroup = _systemDataRepository.Insert(new FoodGroup { Parent = null, IsActive = true }); try { var foodItem = _systemDataRepository.Insert(new FoodItem(primaryFoodGroup) { IsActive = true }); try { var secondaryFoodGroup = _systemDataRepository.Insert(new FoodGroup { Parent = null, IsActive = true }); try { foodItem.IsActive = false; foodItem.FoodGroupAdd(secondaryFoodGroup); _systemDataRepository.Update(foodItem); // ReSharper disable PossibleInvalidOperationException var result = _systemDataRepository.Get <IFoodItem>(foodItem.Identifier.Value); // ReSharper restore PossibleInvalidOperationException Assert.That(result, Is.Not.Null); Assert.That(result.PrimaryFoodGroup, Is.Not.Null); Assert.That(result.PrimaryFoodGroup.Identifier, Is.Not.Null); // ReSharper disable ConditionIsAlwaysTrueOrFalse Assert.That(result.PrimaryFoodGroup.Identifier.HasValue, Is.True); // ReSharper restore ConditionIsAlwaysTrueOrFalse // ReSharper disable PossibleInvalidOperationException Assert.That(result.PrimaryFoodGroup.Identifier.Value, Is.EqualTo(primaryFoodGroup.Identifier.Value)); // ReSharper restore PossibleInvalidOperationException Assert.That(result.IsActive, Is.False); Assert.That(result.FoodGroups, Is.Not.Null); Assert.That(result.FoodGroups, Is.Not.Empty); Assert.That(result.FoodGroups.Count(), Is.EqualTo(2)); Assert.That(result.FoodGroups.SingleOrDefault(fg => fg.Identifier.HasValue && fg.Identifier.Equals(primaryFoodGroup.Identifier)), Is.Not.Null); Assert.That(result.FoodGroups.SingleOrDefault(fg => fg.Identifier.HasValue && fg.Identifier.Equals(secondaryFoodGroup.Identifier)), Is.Not.Null); } finally { _systemDataRepository.Delete(secondaryFoodGroup); } } finally { _systemDataRepository.Delete(foodItem); } } finally { _systemDataRepository.Delete(primaryFoodGroup); } }