コード例 #1
0
        public void ShouldRequireMinimumFields()
        {
            var command = new CreateSource();

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().ThrowAsync <ValidationException>();
        }
コード例 #2
0
        public ActionResult AddSource(CreateSource model)
        {
            Source sou = new Source {
                Name = model.Name, Description = model.Description, Domain = model.Domain, Image = model.Image
            };

            return(Content(repoSou.AddSource(sou).ToString()));
        }
コード例 #3
0
        public async Task ShouldCreateSource()
        {
            //var userId = await RunAsDefaultUserAsync();

            var path = await AddAsync(new Path
            {
                Title       = "Some Path",
                Key         = "some-path",
                Description = "Some Path Description"
            });

            var module = await SendAsync(new CreateModule
            {
                Key         = "module-key",
                Title       = "Module Title",
                Description = "Module Decription"
            });

            var theme = await AddAsync(new Theme
            {
                Title       = "New Theme",
                ModuleId    = module.Id,
                Description = "New Theme Description",
                Necessity   = Necessity.MustKnow,
                Complexity  = Complexity.Beginner,
                Order       = 2
            });

            var command = new CreateSource
            {
                PathId       = path.Id,
                ModuleId     = module.Id,
                ThemeId      = theme.Id,
                Title        = "New Theme",
                Description  = "New Theme Description",
                Url          = "https://www.test.com",
                Type         = SourceType.Book,
                Availability = Availability.RequiresRegistration,
                Relevance    = Relevance.Relevant,
                Order        = 1
            };

            var createdSource = await SendAsync(command);

            var source = await FindAsync <Source>(createdSource.Id);

            source.Should().NotBeNull();
            source.ThemeId.Should().Be(command.ThemeId);
            source.Title.Should().Be(command.Title);
            source.Description.Should().Be(command.Description);
            source.Url.Should().Be(command.Url);
            source.Type.Should().Be(command.Type);
            source.Availability.Should().Be(command.Availability);
            source.Relevance.Should().Be(command.Relevance);
            // source.CreatedBy.Should().Be(userId);
            source.Created.Should().BeCloseTo(DateTime.Now, TimeSpan.FromMilliseconds(1000));
        }
コード例 #4
0
        public async Task Create_ReturnsBadRequest_WhenRequestedPathIdDoesNotMatchCommandId()
        {
            var createCommand = new CreateSource {
                PathId = 1, ModuleId = 1, ThemeId = 1,
                Order  = 0, Title = "Create title", Description = "Create Description", Url = "http://www.ww.ww"
            };
            var controller = new SourcesController(moqMediator.Object);

            var result = await controller.Create(2, 1, 1, createCommand);

            Assert.IsInstanceOf(typeof(BadRequestResult), result.Result);
        }
コード例 #5
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("createSource");
     writer.WriteStringValue(CreateSource.ToSerialString());
     if (Optional.IsDefined(SourceUri))
     {
         writer.WritePropertyName("sourceUri");
         writer.WriteStringValue(SourceUri.AbsoluteUri);
     }
     writer.WriteEndObject();
 }
コード例 #6
0
        public async Task <ActionResult <Source> > Create(int pathId, int moduleId, int themeId,
                                                          [FromBody] CreateSource command)
        {
            if (pathId != command.PathId || moduleId != command.ModuleId || themeId != command.ThemeId)
            {
                return(BadRequest());
            }

            Source model = await Mediator.Send(command);

            return(CreatedAtRoute("GetSource",
                                  new { pathId = command.PathId, moduleId = command.ModuleId, themeId = model.ThemeId, sourceId = model.Id }, model));
        }
コード例 #7
0
        public void ShouldReturnNotFoundForNonExistingTheme()
        {
            var command = new CreateSource
            {
                ModuleId    = 1,
                ThemeId     = 999,
                Title       = "Source Title",
                Description = "Source Decription",
                Url         = "http://www.ww.ww"
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().ThrowAsync <NotFoundException>();
        }
コード例 #8
0
        public void ShouldRequireTitle()
        {
            var command = new CreateSource
            {
                ModuleId    = 1,
                ThemeId     = 1,
                Description = "Source Decription",
                Url         = "http://www.ww.ww"
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().ThrowAsync <ValidationException>()
            .Where(ex => ex.Errors.ContainsKey("Title"))
            .Result.And.Errors["Title"].Should().Contain("Title is required.");
        }
コード例 #9
0
        public void ShouldCheckUrlFormat()
        {
            var command = new CreateSource
            {
                ModuleId    = 1,
                ThemeId     = 1,
                Title       = "Source Title",
                Description = "Source Decription",
                Url         = "http:someinvalidurl"
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().ThrowAsync <ValidationException>()
            .Where(ex => ex.Errors.ContainsKey("Url"))
            .Result.And.Errors["Url"].Should().Contain("URL must be in valid format, e.g. http://www.domain.com.");
        }
コード例 #10
0
        public void ShouldDisallowLongTitle()
        {
            var command = new CreateSource
            {
                ModuleId    = 1,
                ThemeId     = 1,
                Title       = "This source title is too long and exceeds two hundred characters allowed for theme titles by CreateSourceCommandValidator. And this source title in incredibly long and ugly. I imagine no one would create a title this long but just in case",
                Description = "Source Decription",
                Url         = "http://www.ww.ww"
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().ThrowAsync <ValidationException>()
            .Where(ex => ex.Errors.ContainsKey("Title"))
            .Result.And.Errors["Title"].Should().Contain("Title must not exceed 200 characters.");
        }
コード例 #11
0
        public async Task Create_ReturnsCreatedAtRoute()
        {
            var createCommand = new CreateSource {
                PathId = 1, ModuleId = 1, ThemeId = 1,
                Order  = 0, Title = "Create title", Description = "Create Description", Url = "http://www.ww.ww"
            };
            var controller = new SourcesController(moqMediator.Object);

            var result = await controller.Create(1, 1, 1, createCommand);

            var content = GetObjectResultContent <Source>(result.Result);

            Assert.IsInstanceOf(typeof(CreatedAtRouteResult), result.Result);
            Assert.AreEqual("GetSource", ((CreatedAtRouteResult)result.Result).RouteName);
            Assert.IsNotNull(content);
            Assert.AreEqual(1, content.Id);
        }
コード例 #12
0
        public ActionResult EditSource(CreateSource model)
        {
            Source sou = repoSou.GetElements().ToList()[model.Id];

            return(Content(repoSou.EditSource(sou).ToString()));
        }
コード例 #13
0
 VerifyCSharpFix(CreateSource(caseData.args), CreateSource(caseData.fix), allowNewCompilerDiagnostics: true);