public async Task GivenRepository_WhenFullCRUDFlowIsRun_ThenSucceed()
    {
        Execute(Structure.UsersCreateSql);

        var repository = new DapperRepository <User>(DbConnection, new NulloAggregateEventsPublisher());

        var user = new User {
            Id = 0, UserName = "******", FullName = null
        };

        //1. Add
        var result = await repository.Add(user);

        result.Should().NotBe(null);
        result.Id.Should().BeGreaterThan(0);
        result.UserName.Should().Be("*****@*****.**");
        result.FullName.Should().BeNull();

        //2. GetById

        var recordFromDb = await repository.FindById(user.Id);

        recordFromDb.Should().BeEquivalentTo(result);

        //3. Update
        var userToUpdate = new User {
            Id = user.Id, UserName = "******", FullName = "Tom Smith"
        };

        result = await repository.Update(userToUpdate);

        result.Should().NotBe(null);
        result.Id.Should().Be(user.Id);
        result.UserName.Should().Be("*****@*****.**");
        result.FullName.Should().Be("Tom Smith");

        recordFromDb = await repository.FindById(userToUpdate.Id);

        recordFromDb.Should().BeEquivalentTo(result);

        //4. Remove
        result = await repository.Delete(userToUpdate);

        result.Should().NotBe(null);
        result.Id.Should().Be(user.Id);
        result.UserName.Should().Be("*****@*****.**");
        result.FullName.Should().Be("Tom Smith");

        recordFromDb = await repository.FindById(userToUpdate.Id);

        recordFromDb.Should().Be(null);

        //5. Add Range

        var results = (await repository.AddAll(
예제 #2
0
        public virtual async Task <bool> DeleteAsync(int id)
        {
            var item = repository.FindById(id);

            return(await repository.DeleteAsync(item));
        }
예제 #3
0
        public void GivenRepository_WhenFullCRUDFlowIsRun_ThenSucceed()
        {
            Execute(Structure.UsersCreateSql);

            var repository = new DapperRepository <User>(DbConnection);

            var user = new User {
                Id = 0, UserName = "******", FullName = null
            };

            //1. Add
            var result = repository.Add(user);

            result.Should().NotBe(null);
            result.Id.Should().BeGreaterThan(0);
            result.UserName.Should().Be("*****@*****.**");
            result.FullName.Should().BeNull();

            //2. GetById

            var recordFromDb = repository.FindById(user.Id);

            recordFromDb.Should().BeEquivalentTo(result);

            //3. Update
            var userToUpdate = new User {
                Id = user.Id, UserName = "******", FullName = "Tom Smith"
            };

            result = repository.Update(userToUpdate);

            result.Should().NotBe(null);
            result.Id.Should().Be(user.Id);
            result.UserName.Should().Be("*****@*****.**");
            result.FullName.Should().Be("Tom Smith");

            recordFromDb = repository.FindById(userToUpdate.Id);

            recordFromDb.Should().BeEquivalentTo(result);

            //4. Remove
            result = repository.Delete(userToUpdate);

            result.Should().NotBe(null);
            result.Id.Should().Be(user.Id);
            result.UserName.Should().Be("*****@*****.**");
            result.FullName.Should().Be("Tom Smith");

            recordFromDb = repository.FindById(userToUpdate.Id);

            recordFromDb.Should().Be(null);

            //5. Add Range

            var results = repository.AddAll(
                new User {
                UserName = "******"
            },
                new User {
                UserName = "******"
            },
                new User {
                UserName = "******"
            }
                )?.ToList();

            results.Should().NotBeNull();
            results.Should().HaveCount(3);

            results[0].Id.Should().BeGreaterThan(0);
            results[0].UserName.Should().Be("*****@*****.**");
            results[0].FullName.Should().BeNull();

            results[1].Id.Should().BeGreaterThan(0);
            results[1].UserName.Should().Be("*****@*****.**");
            results[1].FullName.Should().BeNull();

            results[2].Id.Should().BeGreaterThan(0);
            results[2].UserName.Should().Be("*****@*****.**");
            results[2].FullName.Should().BeNull();

            //6. Query

            var queryResults = repository.Query().ToList();

            queryResults.Should().Contain(x => results.Select(u => u.Id).Contains(x.Id));

            queryResults = repository.Query().ToList().Where(x => x.UserName == results[1].UserName).ToList();

            queryResults.Should().HaveCountGreaterOrEqualTo(1);
            queryResults.First(x => x.Id == results[1].Id).Should().BeEquivalentTo(results[1]);
        }