Ejemplo n.º 1
0
        public async Task GetAllForResume_WithNoResume_ReturnsNull()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new Resume();

            var skillService = new SkillService(new EfRepository <Resume>(context),
                                                new EfRepository <Skill>(context));

            var result = await skillService.GetByIdAsync(model.Id);

            Assert.Null(result);
        }
Ejemplo n.º 2
0
        public async Task GetAllAsyncWhenNoSkillsReturnsEmptyCollection()
        {
            //Arrange
            var mockSkillRepository = GetDefaultISkillRepositoryInstance();
            var mockUnitOfWork      = GetDefaultIUnitOfWorkInstance();
            var skillId             = 200;

            mockSkillRepository.Setup(r => r.FindById(skillId))
            .Returns(Task.FromResult <Skill>(null));

            var service = new SkillService(mockSkillRepository.Object, mockUnitOfWork.Object);
            //Act
            SkillResponse result = await service.GetByIdAsync(skillId);

            var message = result.Message;

            //Assert
            message.Should().Be("Skill not found");
        }
Ejemplo n.º 3
0
        public async Task GetByIdAsync_WithNoExistingSkill_ReturnsNull()
        {
            string expectedSkillName = "TestSkill";

            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new Skill()
            {
                Name = expectedSkillName
            };

            var skillService = new SkillService(new EfRepository <Resume>(context),
                                                new EfRepository <Skill>(context));

            var result = await skillService.GetByIdAsync(model.Id);

            Assert.Null(result);
        }
Ejemplo n.º 4
0
        public async Task GetByIdAsync_WithExistingSkill_WorksCorrectly()
        {
            string expectedSkillName = "TestSkill";

            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new Skill()
            {
                Name = expectedSkillName
            };

            await context.AddAsync(model);

            context.SaveChanges();

            var skillService = new SkillService(new EfRepository <Resume>(context),
                                                new EfRepository <Skill>(context));

            var result = await skillService.GetByIdAsync(model.Id);

            Assert.Equal(expectedSkillName, result.Name);
        }
Ejemplo n.º 5
0
        public GqlQuery(FehContextFactory dbContextFactory)
        {
            this
            .Field <ListGraphType <GqlAccessory>, List <Accessory> >()
            .Name("accessories")
            .ResolveAsync(
                (context) =>
            {
                var service = new AccessoryService(dbContextFactory.CreateDbContext());

                return(service.GetAllAsync());
            }
                );

            this
            .Field <GqlAccessory, Accessory>()
            .Name("accessory")
            .Argument <NonNullGraphType <GuidGraphType> >("id")
            .ResolveAsync(
                (context) =>
            {
                var id = context.GetArgument <Guid>("id");

                var service = new AccessoryService(dbContextFactory.CreateDbContext());

                return(service.GetByIdAsync(id));
            }
                );

            this
            .Field <ListGraphType <GqlArtist>, List <Artist> >()
            .Name("artists")
            .ResolveAsync(
                (context) =>
            {
                var service = new ArtistService(dbContextFactory.CreateDbContext());

                return(service.GetAllAsync());
            }
                );

            this
            .Field <GqlArtist, Artist>()
            .Name("artist")
            .Argument <NonNullGraphType <IntGraphType> >("id")
            .ResolveAsync(
                (context) =>
            {
                var id = context.GetArgument <int>("id");

                var service = new ArtistService(dbContextFactory.CreateDbContext());

                return(service.GetByIdAsync(id));
            }
                );

            this
            .Field <GqlEnumerations>()
            .Name("enumerations")
            .Resolve(x => new { });

            this
            .Field <ListGraphType <GqlHero>, List <Hero> >()
            .Name("heroes")
            .ResolveAsync(
                (context) =>
            {
                var service = new HeroService(dbContextFactory.CreateDbContext());

                return(service.GetAllAsync());
            }
                );

            this
            .Field <GqlHero, Hero>()
            .Name("hero")
            .Argument <NonNullGraphType <GuidGraphType> >("id")
            .ResolveAsync(
                (context) =>
            {
                var id = context.GetArgument <Guid>("id");

                var service = new HeroService(dbContextFactory.CreateDbContext());

                return(service.GetByIdAsync(id));
            }
                );

            this
            .Field <ListGraphType <GqlItem>, List <Item> >()
            .Name("items")
            .ResolveAsync(
                (context) =>
            {
                var service = new ItemService(dbContextFactory.CreateDbContext());

                return(service.GetAllAsync());
            }
                );

            this
            .Field <GqlItem, Item>()
            .Name("item")
            .Argument <NonNullGraphType <GuidGraphType> >("id")
            .ResolveAsync(
                (context) =>
            {
                var id = context.GetArgument <Guid>("id");

                var service = new ItemService(dbContextFactory.CreateDbContext());

                return(service.GetByIdAsync(id));
            }
                );

            this
            .Field <ListGraphType <GqlSkill>, List <Skill> >()
            .Name("skills")
            .ResolveAsync(
                (context) =>
            {
                var service = new SkillService(dbContextFactory.CreateDbContext());

                return(service.GetAllAsync());
            }
                );

            this
            .Field <GqlSkill, Skill>()
            .Name("skill")
            .Argument <NonNullGraphType <GuidGraphType> >("id")
            .ResolveAsync(
                (context) =>
            {
                var id = context.GetArgument <Guid>("id");

                var service = new SkillService(dbContextFactory.CreateDbContext());

                return(service.GetByIdAsync(id));
            }
                );

            this
            .Field <ListGraphType <GqlVoiceActor>, List <VoiceActor> >()
            .Name("voiceActors")
            .ResolveAsync(
                (context) =>
            {
                var service = new VoiceActorService(dbContextFactory.CreateDbContext());

                return(service.GetAllAsync());
            }
                );

            this
            .Field <GqlVoiceActor, VoiceActor>()
            .Name("voiceActor")
            .Argument <NonNullGraphType <IntGraphType> >("id")
            .ResolveAsync(
                (context) =>
            {
                var id = context.GetArgument <int>("id");

                var service = new VoiceActorService(dbContextFactory.CreateDbContext());

                return(service.GetByIdAsync(id));
            }
                );
        }