Example #1
0
        public async Task GetNestedSimpleResources_GivenDataIsFound_ExpectMaybeWithMappedData()
        {
            var parentDto1 = new SimpleResourceDto
            {
                Id   = Guid.NewGuid(),
                Name = "parent-dto-1",
            };
            var parentDto2 = new SimpleResourceDto
            {
                Id   = Guid.NewGuid(),
                Name = "parent-dto-2",
            };
            var childDto1 = new SimpleResourceDto
            {
                Id               = Guid.NewGuid(),
                Name             = "child-dto-1",
                ParentResourceId = parentDto1.Id,
            };
            var connection = new Mock <IDbConnection>();

            connection.SetupDapperAsync(c => c.QueryAsync <SimpleResourceDto>(
                                            It.IsAny <string>(),
                                            It.IsAny <DynamicParameters>(),
                                            null, null, It.IsAny <CommandType>()))
            .ReturnsAsync(() => new List <SimpleResourceDto>
            {
                parentDto1,
                parentDto2,
                childDto1,
            });

            var dbConnectionProvider = new Mock <IConnectionProvider>();

            dbConnectionProvider.Setup(x => x.GetConnection())
            .Returns(() => connection.Object);

            var roleQueries = new RoleQueries(dbConnectionProvider.Object);
            var result      = await roleQueries.GetNestedSimpleResources();

            Assert.True(result.HasValue);
            Assert.Equal(2, result.Value.Count);
            var parent1 = result.Value.FirstOrDefault(x => x.Name == "parent-dto-1");

            Assert.NotNull(parent1);
            Assert.Equal(parentDto1.Name, parent1.Name);
            Assert.Equal(parentDto1.Id, parent1.Id);
            Assert.Single(parent1.SimpleResources);
            Assert.Equal(childDto1.Name, parent1.SimpleResources.First().Name);
            Assert.Equal(childDto1.Id, parent1.SimpleResources.First().Id);
        }
Example #2
0
        public async Task GetNestedSimpleResources_GivenNoDataIsFound_ExpectMaybeWithNothing()
        {
            var connection = new Mock <IDbConnection>();

            connection.SetupDapperAsync(c => c.QueryAsync <SimpleResourceDto>(
                                            It.IsAny <string>(),
                                            It.IsAny <DynamicParameters>(),
                                            null, null, It.IsAny <CommandType>()))
            .ReturnsAsync(() => new List <SimpleResourceDto>());

            var dbConnectionProvider = new Mock <IConnectionProvider>();

            dbConnectionProvider.Setup(x => x.GetConnection())
            .Returns(() => connection.Object);

            var roleQueries = new RoleQueries(dbConnectionProvider.Object);
            var result      = await roleQueries.GetNestedSimpleResources();

            Assert.True(result.HasNoValue);
        }