Beispiel #1
0
        public void FullCycle()
        {
            // Arrange
            var workplan = CreateWorkplan();

            // Act
            Workplan       loaded, loaded2;
            WorkplanEntity entity1, entity2;

            using (var uow = _factory.Create())
            {
                entity1 = RecipeStorage.SaveWorkplan(uow, workplan);
                uow.SaveChanges();
                loaded = RecipeStorage.LoadWorkplan(uow, entity1.Id);

                loaded.Name = "Modified";

                entity2 = RecipeStorage.SaveWorkplan(uow, loaded);
                uow.SaveChanges();
                loaded2 = RecipeStorage.LoadWorkplan(uow, entity2.Id);
            }

            // Assert
            Assert.AreNotEqual(entity1.Id, entity2.Id);
            Assert.AreEqual(workplan.Id, entity1.Id, "Id not assigned to original object!");
            Assert.AreEqual(workplan.Name, entity1.Name, "Name not correctly stored and saved");
            Assert.AreEqual(loaded.Name, entity2.Name, "Name not correctly stored and saved");
            Assert.AreEqual(loaded.Name, loaded2.Name, "Name not correctly stored and saved");
            Assert.AreEqual(workplan.State, loaded.State);
            Assert.AreEqual(workplan.MaxElementId, loaded.MaxElementId);

            // Compare workplans
            var steps       = workplan.Steps.ToList();
            var loadedSteps = loaded.Steps.ToList();

            foreach (var step in steps)
            {
                var loadedStep = loadedSteps.FirstOrDefault(s => s.Id == step.Id);
                Assert.NotNull(loadedStep);
                Assert.AreEqual(step.GetType(), loadedStep.GetType());
                for (int index = 0; index < step.Inputs.Length; index++)
                {
                    Assert.AreEqual(step.Inputs[index].Id, loadedStep.Inputs[index].Id);
                    Assert.AreEqual(step.Inputs[index].Name, loadedStep.Inputs[index].Name);
                }
                for (int index = 0; index < step.Outputs.Length; index++)
                {
                    Assert.AreEqual(step.Outputs[index].Id, loadedStep.Outputs[index].Id);
                    Assert.AreEqual(step.Outputs[index].Name, loadedStep.Outputs[index].Name);
                }
            }
        }