Exemple #1
0
        public async Task <Result> Handle(CreateProductionSiteCommand request, CancellationToken cancellationToken)
        {
            Result result;
            var    id = _identifierProvider.Generate();

            var productionSiteToCreate = new ProductionSite(id, request.Code, request.Name, request.Source);

            productionSiteToCreate.Version = _versionProvider.Generate();

            try
            {
                await _productionSiteWriteRepository.CreateAsync(productionSiteToCreate);

                result = Result.Ok(id, productionSiteToCreate.Version);
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.CodeSourceConflict,
                        Target  = "code-source"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateProductionSiteFailure);
            }

            return(result);
        }
        public void CreateProductionSiteShouldSucceed()
        {
            // Arrange
            var name = "ProductionSite";

            // Act
            var result = new ProductionSite(name);

            // Assert
            result.Name.Should().Be(name);
        }
        public void TwoProductionSitesWithDistinctValuesShouldBeNotEqualThroughOperator()
        {
            // Arrange
            var firstName  = "Production Site 1";
            var secondName = "Production Site 2";
            var first      = new ProductionSite(firstName);
            var second     = new ProductionSite(secondName);

            // Act
            var result = first != second;

            // Assert
            result.Should().BeTrue();
        }
        public void TwoProductionSitesWithDistinctValuesShouldBeNotEqualThroughMethod()
        {
            // Arrange
            var firstName  = "Production Site 1";
            var secondName = "Production Site 2";
            var first      = new ProductionSite(firstName);
            var second     = new ProductionSite(secondName);

            // Act
            var result = first.Equals(second);

            // Assert
            result.Should().BeFalse();
        }
        public void TwoProductionSitesWithSameValuesShouldBeEqualThroughOperator()
        {
            // Arrange
            var name = "Production Site";

            var first  = new ProductionSite(name);
            var second = new ProductionSite(name);

            // Act
            var result = first == second;

            // Assert
            result.Should().BeTrue();
        }
        public void CreateProductionSiteShouldSucceed()
        {
            // Arrange
            var id     = Guid.NewGuid();
            var code   = "Production site";
            var name   = "Description";
            var source = "Belgium";

            // Act
            var result = new ProductionSite(id, code, name, source);

            // Assert
            result.Name.Should().Be(name);
        }
        public async Task CreateShouldSucceedWhenNameIsSame()
        {
            //Arrange
            var name = "TestName";

            var productionSite = new ProductionSite(Guid.NewGuid(), "TestCode1", name, "TestSource1");
            await _repository.CreateAsync(productionSite);

            var productionSite2 = new ProductionSite(Guid.NewGuid(), "TestCode2", name, "TestSource2");
            //Act
            Action act = () => { _repository.CreateAsync(productionSite2).GetAwaiter().GetResult(); };

            //Assert
            act.Should().NotThrow();
        }
        public async Task CreateShouldFailWhenCodeAndSourceSame()
        {
            //Arrange
            var code   = "TestCode";
            var name   = "TestName";
            var source = "TestSource";

            var productionSite = new ProductionSite(Guid.NewGuid(), code, name, source);
            await _repository.CreateAsync(productionSite);

            var productionSite2 = new ProductionSite(Guid.NewGuid(), code, name, source);
            //Act
            Action act = () => { _repository.CreateAsync(productionSite2).GetAwaiter().GetResult(); };

            //Assert
            act.Should().Throw <UniqueKeyException>();
        }
            public static ProductionSite CreateProductionSite(string code, string name, string source)
            {
                // prepare
                var writeRepository = new ProductionSiteWriteRepository(new DataContext(new PersistenceConfiguration(RepositoryTestsHelper.ConnectionString)));
                var readRepository  = new ProductionSiteReadRepository(new DataContext(new PersistenceConfiguration(RepositoryTestsHelper.ConnectionString)));

                // create
                var productionSite = new ProductionSite(Guid.NewGuid(), code, name, source);
                IEnumerable <ProductionSite> productionSites = new List <ProductionSite>()
                {
                    productionSite
                };

                productionSites.ToList().ForEach(x => writeRepository.CreateAsync(x).GetAwaiter().GetResult());

                // result
                var result = readRepository.GetAsync(productionSite.Id).Result;

                return(result);
            }
        public async Task CreateShouldSucceed()
        {
            //Arrange
            var code   = "TestCode";
            var name   = "TestName";
            var source = "TestSource";

            var productionSite = new ProductionSite(Guid.NewGuid(), code, name, source);

            //Act
            await _repository.CreateAsync(productionSite);

            //Asssert
            var data = RepositoryHelper.ForProductionSite.GetProductionSites();

            data.Should().HaveCount(1);
            var result = data.First();

            result.Name.Should().Be(name);
            result.Code.Should().Be(code);
            result.Source.Should().Be(source);
        }