Example #1
0
 public void SetUp()
 {
     _service = new Mock <IGetModuleService>();
     _query   = new GetModuleQuery {
         ModuleId = "moduleId"
     };
     _sut = new GetModuleQueryHandler(_service.Object);
 }
Example #2
0
        public void ModuleIdISNullOrEmpty_ShouldHaveError(string moduleId)
        {
            var query = new GetModuleQuery {
                ModuleId = moduleId
            };

            _sut.ShouldHaveValidationErrorFor(x => x.ModuleId, query);
        }
Example #3
0
        public void ValidModuleId_ShouldNotHaveError()
        {
            var query = new  GetModuleQuery {
                ModuleId = "moduleId"
            };

            _sut.ShouldNotHaveValidationErrorFor(x => x.ModuleId, query);
        }
Example #4
0
        public void ShouldReturnNotFound_WhenPathIdNotFound()
        {
            var query = new GetModuleQuery()
            {
                PathKey = "99999", Id = 1
            };

            FluentActions.Invoking(() =>
                                   SendAsync(query)).Should().ThrowAsync <NotFoundException>();
        }
Example #5
0
        public void GetOne_ShouldThrow_WhenCanceled()
        {
            var cts = new CancellationTokenSource();

            cts.Cancel();

            var query = new GetModuleQuery()
            {
                PathKey = "some-path", Id = 1
            };

            FluentActions.Invoking(() =>
                                   SendAsync(query, cts.Token)).Should().ThrowAsync <TaskCanceledException>();
        }
Example #6
0
        public async Task ShouldRemoveModuleFromPath()
        {
            var module = await AddAsync(new Module
            {
                Title       = "New Module",
                Key         = "module-key",
                Description = "New Module Description",
                Tags        = new List <string> {
                    "Tag1", "Tag2", "Tag3"
                },
                Paths = new List <Path> {
                    new Path
                    {
                        Title       = "Some Path1",
                        Key         = "some-path1",
                        Description = "Some Path Description"
                    },
                    new Path
                    {
                        Title       = "Some Path2",
                        Key         = "some-path2",
                        Description = "Some Path Description"
                    }
                }
            });

            var query = new GetModuleQuery()
            {
                PathKey = "some-path1", Id = module.Id
            };
            var moduleAdded = await SendAsync(query);

            await SendAsync(new DeleteModule
            {
                PathId = module.Paths.FirstOrDefault().Id,
                Id     = module.Id
            });

            query = new GetModuleQuery()
            {
                PathKey = "some-path1", Id = module.Id
            };
            var moduleRemovedFromPath1 = await SendAsync(query);

            moduleAdded.Should().NotBeNull();
            moduleAdded.Paths.Should().HaveCount(2);
            moduleRemovedFromPath1.Should().NotBeNull();
            moduleRemovedFromPath1.Paths.Should().HaveCount(1);
        }
Example #7
0
        public async Task GetOne_ShouldReturnModule()
        {
            var module = await SendAsync(new CreateModule
            {
                Title       = "New Module",
                Key         = "module-key",
                Description = "New Module Description",
                Necessity   = Necessity.MustKnow,
                Tags        = new List <string> {
                    "Tag1", "Tag2", "Tag3"
                }
            });

            var query = new GetModuleQuery()
            {
                PathKey = "some-path", Id = module.Id
            };

            var result = await SendAsync(query);

            result.Title.Should().NotBeEmpty();
            result.Description.Should().NotBeEmpty();
            result.Tags.Should().HaveCount(3);
        }
Example #8
0
 public async Task <List <Module> > Handle(GetModuleQuery request, CancellationToken cancellationToken)
 {
     return(await _dbContext.Module.ToListAsync());
 }