public void It_returns_new_context_object_id()
        {
            var objectId = ObjectId.NewUniqueId();
            var composite = new CompositeCommandExecutionContext();

            var contextReference = composite.GetFor(objectId);

            Assert.IsNotNull(contextReference);
        }
        public void It_return_all_unempty_contexts()
        {
            var composite = new CompositeCommandExecutionContext();
            composite.GetFor(ObjectId.NewUniqueId()).Create(ObjectTypeId.NewUniqueId());
            composite.GetFor(ObjectId.NewUniqueId()).Create(ObjectTypeId.NewUniqueId());
            composite.GetFor(ObjectId.NewUniqueId());

            Assert.AreEqual(2, composite.GetAll().Count());
        }
        public void It_returns_new_context_object_id()
        {
            var objectId  = ObjectId.NewUniqueId();
            var composite = new CompositeCommandExecutionContext();

            var contextReference = composite.GetFor(objectId);

            Assert.IsNotNull(contextReference);
        }
        public void It_returns_same_instance_of_context_for_particular_object_id()
        {
            var objectId = ObjectId.NewUniqueId();
            var composite = new CompositeCommandExecutionContext();

            var firstReference = composite.GetFor(objectId);
            var secondReference = composite.GetFor(objectId);

            Assert.AreSame(firstReference, secondReference);
        }
        public void It_return_all_unempty_contexts()
        {
            var composite = new CompositeCommandExecutionContext();

            composite.GetFor(ObjectId.NewUniqueId()).Create(ObjectTypeId.NewUniqueId());
            composite.GetFor(ObjectId.NewUniqueId()).Create(ObjectTypeId.NewUniqueId());
            composite.GetFor(ObjectId.NewUniqueId());

            Assert.AreEqual(2, composite.GetAll().Count());
        }
        public void It_returns_same_instance_of_context_for_particular_object_id()
        {
            var objectId  = ObjectId.NewUniqueId();
            var composite = new CompositeCommandExecutionContext();

            var firstReference  = composite.GetFor(objectId);
            var secondReference = composite.GetFor(objectId);

            Assert.AreSame(firstReference, secondReference);
        }
        public void After_executing_commands_all_objects_of_requested_type_are_present_in_the_composite_context()
        {
            var requestedType = ObjectTypeId.NewUniqueId();

            var collection = new CommandsByObjectTypeCollection();
            var commandExecutor = new CommandExecutor()
                .RegisterCommandHandler(new CreateObjectCommandHandler())
                .RegisterCommandHandler(new ModifyAttributeCommandHandler());

            collection.Add(new CreateObjectCommand(requestedType, ObjectId.NewUniqueId()));
            collection.Add(new CreateObjectCommand(requestedType, ObjectId.NewUniqueId()));

            collection.Add(new CreateObjectCommand(ObjectTypeId.NewUniqueId(), ObjectId.NewUniqueId()));
            collection.Add(new CreateObjectCommand(ObjectTypeId.NewUniqueId(), ObjectId.NewUniqueId()));

            var compositeContext = new CompositeCommandExecutionContext();

            collection.ExecuteCommands(requestedType, commandExecutor, compositeContext);

            var objectStates = compositeContext.GetAll();
            Assert.AreEqual(2, objectStates.Count(x => x.TypeId == requestedType));
        }
        public void After_executing_commands_all_objects_of_requested_type_are_present_in_the_composite_context()
        {
            var requestedType = ObjectTypeId.NewUniqueId();

            var collection      = new CommandsByObjectTypeCollection();
            var commandExecutor = new CommandExecutor()
                                  .RegisterCommandHandler(new CreateObjectCommandHandler())
                                  .RegisterCommandHandler(new ModifyAttributeCommandHandler());

            collection.Add(new CreateObjectCommand(requestedType, ObjectId.NewUniqueId()));
            collection.Add(new CreateObjectCommand(requestedType, ObjectId.NewUniqueId()));

            collection.Add(new CreateObjectCommand(ObjectTypeId.NewUniqueId(), ObjectId.NewUniqueId()));
            collection.Add(new CreateObjectCommand(ObjectTypeId.NewUniqueId(), ObjectId.NewUniqueId()));

            var compositeContext = new CompositeCommandExecutionContext();

            collection.ExecuteCommands(requestedType, commandExecutor, compositeContext);

            var objectStates = compositeContext.GetAll();

            Assert.AreEqual(2, objectStates.Count(x => x.TypeId == requestedType));
        }