コード例 #1
0
        public async void SearchAsyncWithSearchString_GivenProjectsExist_ReturnsProjects()
        {
            var projects = new Project[]
            {
                new Project()
                {
                    Title = "TestOne", Description = "Descritpion", CreatedDate = System.DateTime.UtcNow, CreatorId = creator.Id
                },
                new Project()
                {
                    Title = "T3st", Description = "TestTwo", CreatedDate = System.DateTime.UtcNow, CreatorId = creator.Id
                },
                new Project()
                {
                    Title = "Title", Description = "Descritpion", CreatedDate = System.DateTime.UtcNow, CreatorId = creator.Id
                }
            };

            context.Projects.AddRange(projects);
            context.SaveChanges();

            //SanityCheck
            Assert.Equal(3, await context.Projects.CountAsync());

            using (var repo1 = new ProjectRepository(context))
            {
                var results = await repo1.SearchAsync("test");

                Assert.Equal(2, results.Count());
                Assert.Equal("TestOne", results.ToArray()[0].Title);
                Assert.Equal("T3st", results.ToArray()[1].Title);
            }
        }
コード例 #2
0
        public async void DeleteAsync_GivenCategoryExistsAndInNoProjects_ReturnsSuccess()
        {
            var locationToDelete = new Location
            {
                Id      = 1,
                City    = "Sydney",
                Country = "Australia"
            };

            locationRepository = new LocationRepository(setupContextForIntegrationTests());

            context.Locations.Add(locationToDelete);
            context.SaveChanges();

            //Sanity Check
            Assert.NotNull(context.Locations.Find(locationToDelete.Id));
            Assert.Empty(await context.Projects.ToArrayAsync());

            using (var logic = new LocationLogic(locationRepository, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var response = await logic.DeleteAsync(locationToDelete.Id);

                Assert.Equal(ResponseLogic.SUCCESS, response);
            }
        }
コード例 #3
0
        public async void CreateAsync(UserCreateDTO user, String azureUId, ResponseLogic expected)
        {
            var existingUser = new User()
            {
                Id = 1, Firstname = "IAlready", Surname = "Exist", Mail = "*****@*****.**", AzureUId = "existingAuzreUId"
            };
            var existingLocation = new Location()
            {
                Id = 1, City = "Sydney", Country = "Australia"
            };

            userRepository     = new UserRepository(setupContextForIntegrationTests());
            skillRepository    = new SkillRepository(context);
            projectRepository  = new ProjectRepository(context);
            locationRepository = new LocationRepository(context);

            var locationLogic = new LocationLogic(locationRepository, userRepository, projectRepository);

            context.Users.Add(existingUser);
            context.Locations.Add(existingLocation);
            context.SaveChanges();

            //SanityCheck
            Assert.Equal(1, await context.Users.CountAsync());
            Assert.Equal(existingUser, await context.Users.FirstAsync());
            Assert.Equal(1, await context.Locations.CountAsync());
            Assert.Equal(existingLocation, await context.Locations.FirstAsync());

            using (var logic = new UserLogic(userRepository, skillLogicMock.Object, sparkLogicMock.Object, locationLogic))
            {
                var result = await logic.CreateAsync(user, azureUId);

                Assert.Equal(expected, result);
            }
        }
コード例 #4
0
        public async void ReadAsync_GivenLocationsExist_ReturnsLocations()
        {
            var locations = new Location[]
            {
                new Location()
                {
                    Id = 1, City = "Sydney", Country = "Australia"
                },
                new Location()
                {
                    Id = 2, City = "Brisbane", Country = "Australia"
                }
            };

            context.Locations.AddRange(locations);
            context.SaveChanges();

            //SanityCheck
            Assert.Equal(2, await context.Locations.CountAsync());

            using (var repo = new LocationRepository(context))
            {
                var results = await repo.ReadAsync();

                Assert.Equal(2, results.Count);
            }
        }
コード例 #5
0
        public async void AddSkillAsync_GivenSkillAndProjectExist_ReturnsSUCCESS()
        {
            var existingUser = new User()
            {
                Id = 1, Firstname = "IAlready", Surname = "Exist", Mail = "*****@*****.**", AzureUId = "existingAuzreUId"
            };
            var existingSkill = new Skill()
            {
                Id = 1, Name = "Dancing"
            };
            var existingProject = new Project()
            {
                Id = 1, Title = "Foo", Description = "Bar", Creator = existingUser, CreatedDate = System.DateTime.UtcNow
            };

            locationRepository = new LocationRepository(setupContextForIntegrationTests());
            skillRepository    = new SkillRepository(context);
            projectRepository  = new ProjectRepository(context);
            userRepository     = new UserRepository(context);

            var skillLogic = new SkillLogic(skillRepository, userRepository, projectRepository);

            context.Users.Add(existingUser);
            context.SaveChanges();
            context.Skills.Add(existingSkill);
            context.Projects.Add(existingProject);
            context.SaveChanges();
            context.Entry(existingSkill).State = EntityState.Detached;

            //SanityCheck
            Assert.Equal(1, await context.Users.CountAsync());
            Assert.Equal(existingUser, await context.Users.FirstAsync());
            Assert.Equal(1, await context.Projects.CountAsync());
            Assert.Equal(existingProject, await context.Projects.FirstAsync());
            Assert.Equal(1, await context.Skills.AsNoTracking().CountAsync());

            using (var logic = new ProjectLogic(projectRepository, locationRepository, skillLogic, sparkLogicMock.Object, locationLogicMock.Object, categoryLogicMock.Object))
            {
                var result = await logic.AddSkillAsync(1, new SkillDTO()
                {
                    Id = 1, Name = "Dancing"
                }, existingUser.Id);

                Assert.Equal(ResponseLogic.SUCCESS, result);
            }
        }
コード例 #6
0
        public async void CreateAsync_GivenValidAttachment_ReturnsNewAttachmentId()
        {
            var attachmentToCreate = new AttachmentCreateDTO
            {
                Description = "An example attachment",
                Data        = "fuvwygwiu gbuywgykaguygdchjbaeiuyxgciuyadhviu bwrhjdsiyeabfcuyuw wyadvfjcvyut3er78t2euabdcbeaiyc eqdcgfw",
                Type        = (int)AttachmentTypes.BITMAP,
                ProjectId   = 1
            };

            var user = new User()
            {
                Id = 1, Firstname = "John", Surname = "Smith", AzureUId = "rfaweaw", Mail = "*****@*****.**"
            };
            var project = new Project()
            {
                Id = 1, Title = "Foo", Description = "Bar", Creator = user, CreatedDate = System.DateTime.UtcNow
            };

            context.Projects.Add(project);
            context.SaveChanges();

            //SanityCheck
            Assert.NotNull(context.Projects.AsNoTracking().Where(p => p.Id == 1).First());

            using (var repository = new AttachmentRepository(context))
            {
                var id = await repository.CreateAsync(attachmentToCreate);

                Assert.Equal((await context.Attachments.FirstAsync()).Id, id);
            }
        }
コード例 #7
0
        public async void DeleteAsync_GivenCategoryExistsAndInNoProjects_ReturnsSuccess()
        {
            var categoryToDelete = new Category
            {
                Id   = 1,
                Name = "Category"
            };

            categoryRepository = new CategoryRepository(setupContextForIntegrationTests());

            context.Categories.Add(categoryToDelete);
            context.SaveChanges();

            //Sanity Check
            Assert.NotNull(context.Categories.Find(categoryToDelete.Id));
            Assert.Empty(await context.Projects.ToArrayAsync());

            using (var logic = new CategoryLogic(categoryRepository, projectRepositoryMock.Object))
            {
                var response = await logic.DeleteAsync(categoryToDelete.Id);

                Assert.Equal(ResponseLogic.SUCCESS, response);
            }
        }
コード例 #8
0
        public ProjectRepositoryTests()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            var builder = new DbContextOptionsBuilder <CrowdSparkContext>()
                          .UseSqlite(connection);

            context = new CrowdSparkContext(builder.Options);
            context.Database.EnsureCreated();

            context.Database.BeginTransaction();

            creator = new User()
            {
                Id = 1, Firstname = "Test", Surname = "Surname", Mail = "*****@*****.**", AzureUId = "blahblahblah"
            };
            context.Users.Add(creator);
            context.SaveChanges();
        }
コード例 #9
0
        public async void SearchAsync_GivenMatchingSkills_ReturnsSkills()
        {
            var existingSkills = new Skill[]
            {
                new Skill()
                {
                    Id = 1, Name = "Cooking"
                },
                new Skill()
                {
                    Id = 2, Name = "Cooking Bacon"
                },
                new Skill()
                {
                    Id = 3, Name = "Burning things while trying to cook"
                },
                new Skill()
                {
                    Id = 4, Name = "Yoddeling"
                }
            };

            skillRepository = new SkillRepository(setupContextForIntegrationTests());

            context.Skills.AddRange(existingSkills);
            context.SaveChanges();

            //Sanity Check
            Assert.Equal(4, await context.Skills.CountAsync());

            using (var logic = new SkillLogic(skillRepository, userRepositoryMock.Object, projectRepositoryMock.Object))
            {
                var results = await logic.SearchAsync("cook");

                Assert.Equal(3, results.Count());
                Assert.Equal(existingSkills[0].Name, results.ToArray()[0].Name);
                Assert.Equal(existingSkills[1].Name, results.ToArray()[1].Name);
                Assert.Equal(existingSkills[2].Name, results.ToArray()[2].Name);
            }
        }