예제 #1
0
        public void Go()
        {
            var createProductCommand = new CreateProductCommand { Name = "Hello" };
            this.createProductCommandHandler.Handle(createProductCommand);
            Console.WriteLine(createProductCommand.CreatedProductId);

            var createProductVersionCommand = new CreateProductVersionCommand { ProductId = createProductCommand.CreatedProductId, Version = "World" };
            this.createProductVersionCommandHandler.Handle(createProductVersionCommand);
            Console.WriteLine(createProductVersionCommand.CreatedProductVersionId);
        }
        public void TestHandleSavesNewProductVersionInSet()
        {
            var repository = RepositoryFactory.GetInstance<ProductVersion, int>();

            var uow = new Mock<IUnitOfWork>();
            uow.SetupGet(u => u.ProductVersions).Returns(repository);

            var factory = new Mock<IUnitOfWorkFactory>();
            factory.Setup(f => f.CreateNew()).Returns(uow.Object);

            var command = new CreateProductVersionCommand
            {
                ProductId = new Random().Next(),
                Version = Guid.NewGuid().ToString()
            };

            var handler = new CreateProductVersionCommandHandler(factory.Object);

            handler.Handle(command);

            Assert.IsTrue(repository.Exists(p => p.Version == command.Version && p.ProductId == command.ProductId));
        }