Exemple #1
0
        private async Task <IRepository> GetRepoToSearch()
        {
            var repo = new MockRepository();
            await repo.CommitAsync(GetCompaniesToSearch());

            return(repo);
        }
        public async Task ShouldFindCorrectCompanyByIsin()
        {
            var company1 = new Domain.Entities.Company()
            {
                Isin = "test1"
            };
            var company2 = new Domain.Entities.Company {
                Isin = "test2"
            };
            var repo = new MockRepository();
            await repo.CommitAsync(company1, company2);

            var result = await new FindCompanyByIsinQueryHandler(repo).Handle(new FindCompanyByIsinQuery("test1"), default);

            Assert.Equal(company1, result);
        }
Exemple #3
0
        public async Task ShouldThrowExistingIsinIfExists()
        {
            var repo = new MockRepository();
            await repo.CommitAsync(new Domain.Entities.Company()
            {
                Isin = "TEST"
            });

            await Assert.ThrowsAsync <IsinExistsException>(
                () => new CreateCompanyCommandHandler(repo).Handle(
                    new CreateCompanyCommand(
                        new Domain.Entities.Company()
            {
                Isin = "TEST"
            }), default));
        }
        public async Task ShouldReturnCorrectCompany()
        {
            var company1 = new Domain.Entities.Company()
            {
                Id = 1
            };
            var company2 = new Domain.Entities.Company {
                Id = 2
            };
            var repo = new MockRepository();
            await repo.CommitAsync(company1, company2);

            var result = await new FindCompanyByIdQueryHandler(repo).Handle(new FindCompanyByIdQuery(2), default);

            Assert.Equal(company2, result);
        }
Exemple #5
0
        public async Task ShouldThrowIsinExistsExceptionIfAnotherCompanyHasIsin()
        {
            var company1 = new Domain.Entities.Company()
            {
                Id = 1, Isin = "test1"
            };
            var company2 = new Domain.Entities.Company {
                Id = 2, Isin = "test2"
            };
            var repo = new MockRepository();
            await repo.CommitAsync(company1, company2);

            await Assert.ThrowsAsync <IsinExistsException>(() => GetHandler(repo).Handle(
                                                               new UpdateCompanyCommand(new Domain.Entities.Company()
            {
                Id   = 2,
                Isin = "test1"
            }), default));
        }
Exemple #6
0
        public async Task ShouldUpdateCompanyName()
        {
            var company1 = new Domain.Entities.Company()
            {
                Id = 1, Isin = "test1"
            };
            var company2 = new Domain.Entities.Company {
                Id = 2, Isin = "test2", Name = "John .Inc"
            };
            var repo = new MockRepository();
            await repo.CommitAsync(company1, company2);

            await GetHandler(repo).Handle(new UpdateCompanyCommand(new Domain.Entities.Company()
            {
                Id   = 2,
                Name = "Jane .Inc"
            }), default);

            var actual = await repo.FindAsync <Domain.Entities.Company>(c => c.Id == 2);

            Assert.Equal("Jane .Inc", actual.Name);
        }