예제 #1
0
        public async Task CreateSection_ReturnsCreatedSection()
        {
            var section = new Section
            {
                SectionString = "Section 1",
                Instructor    = new Instructor {
                    FirstName = "Tom", LastName = "Capaul"
                }
            };

            var service = new Mock <ISectionService>();

            service.Setup(x => x.AddSection(It.Is <Section>(g => g.SectionString == section.SectionString)))
            .Returns(Task.FromResult(new Section
            {
                SectionString = section.SectionString
            }))
            .Verifiable();

            var controller = new SectionsController(service.Object, Mapper.Instance);

            var     result      = (await controller.AddSection(Mapper.Map <SectionInputViewModel>(section))).Result as OkObjectResult;
            Section resultValue = (Section)result.Value;

            Assert.IsNotNull(resultValue);
            Assert.AreEqual("Section 1", resultValue.SectionString);
            Assert.AreEqual("Tom", resultValue.Instructor.FirstName);
            Assert.AreEqual("Capaul", resultValue.Instructor.LastName);
            service.VerifyAll();
        }
예제 #2
0
        public void TestExistingSubmissionSection()
        {
            // Arrange
            var repo       = InitRepo();
            var controller = new SectionsController(repo);
            var formData   = new Dictionary <int, string>()
            {
                { 1, "test" },
                { 2, "test2" },
                { 3, "test3" }
            };

            // Act
            controller.Put(1, 1, 1, 1, formData);

            // Assert
            var oldResponses                   = repo.Get <SubmissionEntity>().First().SubmissionSections.First().FieldResponses;
            var fieldEntityResponse            = repo.GetOne <FieldEntity>(r => r.Id == 1);
            var fieldSetResponsibilityResponse = repo.GetOne <FieldSetResponseEntity>(r => r.SubmissionId == 1 &&
                                                                                      r.SectionId == 1 &&
                                                                                      r.FieldId == 1 &&
                                                                                      r.FieldSetValueCd.Equals("13-other"));

            Assert.AreEqual("test", oldResponses.First(r => r.FieldId == 1).Text);
            Assert.AreEqual("test2", oldResponses.First(r => r.FieldId == 2).Text);
            Assert.AreEqual("test3", repo.GetOne <FieldResponseEntity>(r => r.SubmissionId == 1 && r.SectionId == 1 && r.FieldId == 3).Text);
            Assert.AreEqual("checkbox", fieldEntityResponse.FieldTypeCode);
            Assert.AreEqual(1, fieldSetResponsibilityResponse.SelectedInd);
        }
예제 #3
0
        public async Task UpdateSection_ReturnsUpdatedSection()
        {
            var section = new Section
            {
                SectionString = "Section 1",
                Instructor    = new Instructor {
                    FirstName = "Tom", LastName = "Capaul"
                }
            };
            var service = new Mock <ISectionService>();

            service.Setup(x => x.AddSection(It.Is <Section>(g => g.SectionString == section.SectionString)))
            .Returns(Task.FromResult(new Section
            {
                SectionString = section.SectionString
            }))
            .Verifiable();

            var controller = new SectionsController(service.Object, Mapper.Instance);

            var result = (await controller.UpdateSection(1, Mapper.Map <SectionInputViewModel>(section)));

            Assert.IsNotNull(result);
            service.VerifyAll();
        }
예제 #4
0
        public void TestNewSubmission()
        {
            // Arrange
            var repo       = InitRepo();
            var controller = new SectionsController(repo);
            var formData   = new Dictionary <int, string>()
            {
                { 1, "test" },
                { 2, "test2" },
                { 3, "test3" }
            };

            // Act
            controller.Put(1, 1, 6, 2, formData);

            // Assert
            var submission = repo.GetOne <SubmissionEntity>(s => s.UserId == 2);

            Assert.IsNotNull(submission);

            var section = repo.GetOne <SubmissionSectionEntity>(s => s.SectionId == 6);

            Assert.IsNotNull(section);

            var responses = repo.Get <FieldResponseEntity>(r => r.SectionId == 6);

            Assert.AreEqual(3, responses.Count);
            Assert.AreEqual("test", responses.First(r => r.FieldId == 1).Text);
            Assert.AreEqual("test2", responses.First(r => r.FieldId == 2).Text);
            Assert.AreEqual("test3", responses.First(r => r.FieldId == 3).Text);
        }
예제 #5
0
        public async Task CreateSection_RequiresSection()
        {
            var service    = new Mock <ISectionService>();
            var controller = new SectionsController(service.Object, Mapper.Instance);

            var result = (await controller.AddSection(null)).Result as BadRequestResult;

            Assert.IsNotNull(result);
        }
예제 #6
0
        public async Task DeleteSection_RequiresPositiveId(int sectionId)
        {
            var service    = new Mock <ISectionService>(MockBehavior.Strict);
            var controller = new SectionsController(service.Object, Mapper.Instance);

            var result = await controller.DeleteSection(sectionId);

            Assert.IsTrue(result is BadRequestObjectResult);
        }
예제 #7
0
        public void TestSubmitted()
        {
            // Arrange
            var controller = new SectionsController(InitRepo());

            // Act
            var section = controller.Get(1, 1, 1, 2);

            // Asserts
            var field = section.Fields.ElementAt(0);

            Assert.IsTrue(string.IsNullOrEmpty(((TextField)field).Value));
        }
예제 #8
0
        public void TestAddFields()
        {
            // Arrange
            var controller = new SectionsController(InitRepo());

            // Act
            var sections = controller.Get(1, 1, true, 1);

            // Asserts
            Assert.IsNotNull(sections.Last().Fields);
            Assert.AreEqual(2, sections.Last().Fields.Count());
            Assert.AreEqual("Textbox Test", ((TextField)sections.First().Fields.First()).Value);
        }
예제 #9
0
        public async System.Threading.Tasks.Task GetSectionByIdTestAsync()
        {
            var mockSectionService = new Mock <ISectionService>();
            var mock   = new Mock <SectionsController>();
            var result = mock.Object.GetSectionById(new Guid("cc23adcf-bd12-4a27-9f1e-cedd2a476818"));
            //var mockUserManager = new Mock<UserManager<User>>();
            var mockLoggerManager = new Mock <ILoggerManager>();
            var mockMapper        = new Mock <IMapper>();
            var controller        = new SectionsController(mockSectionService.Object, mockLoggerManager.Object, mockMapper.Object, null);

            //var result = await controller.GetSectionById(new Guid("cc23adcf-bd12-4a27-9f1e-cedd2a476818"));
            Assert.IsNotNull(result);
        }
예제 #10
0
        public async Task DeleteSection_ReturnsOkWhenSectionIsDeleted()
        {
            var service = new Mock <ISectionService>();

            service.Setup(x => x.DeleteSection(2))
            .Returns(Task.FromResult(true))
            .Verifiable();
            var controller = new SectionsController(service.Object, Mapper.Instance);

            var result = await controller.DeleteSection(2);

            Assert.IsTrue(result is OkResult);
            service.VerifyAll();
        }
예제 #11
0
        public async Task DeleteSection_ReturnsNotFoundWhenTheSectionFailsToDelete()
        {
            var service = new Mock <ISectionService>();

            service.Setup(x => x.DeleteSection(2))
            .Returns(Task.FromResult(false))
            .Verifiable();
            var controller = new SectionsController(service.Object, Mapper.Instance);

            var result = await controller.DeleteSection(2);

            Assert.IsTrue(result is NotFoundResult);
            service.VerifyAll();
        }
예제 #12
0
        public void TestNoLanguage()
        {
            // Arrange
            var controller = new SectionsController(InitRepo());

            // Act
            var section = controller.Get(1, 1, 2);
            var field   = section.Fields.First();

            // Assert
            Assert.IsNull(section.Label);
            Assert.AreEqual(2, section.Labels.Count());
            Assert.IsNull(field.Label);
            Assert.AreEqual(2, field.Labels.Count());
        }
예제 #13
0
        public void GetSectionsForProgram()
        {
            // Arrange
            var controller = new SectionsController(InitRepo());

            // Act
            var sections = controller.Get(1, 1);

            // Asserts
            Assert.IsNotNull(sections);
            Assert.AreEqual(2, sections.Count());
            Assert.AreEqual(1, sections.First().Id);
            Assert.AreEqual(2, sections.First().NextSectionId);
            Assert.IsNull(sections.First().PreviousSectionId);
            Assert.AreEqual(1, sections.Last().PreviousSectionId);
            Assert.IsNull(sections.Last().NextSectionId);
            Assert.IsNull(sections.Last().Fields);
        }
예제 #14
0
        public void GetSection()
        {
            // Arrange
            var controller = new SectionsController(InitRepo());

            controller.SetHeaders(new Dictionary <string, string>
            {
                { "ACCEPT-LANGUAGE", "en" }
            });

            // Act
            var section = controller.Get(1, 1, 2);

            // Asserts
            Assert.IsNotNull(section);
            Assert.AreEqual("Section 2", section.Label);
            Assert.IsNotNull(section.Fields);
            Assert.AreEqual(2, section.Fields.Count);
            Assert.AreEqual(2, section.Fields.First().Id);
        }
예제 #15
0
        public void TestFrench()
        {
            // Arrange
            var controller = new SectionsController(InitRepo());

            controller.SetHeaders(new Dictionary <string, string>
            {
                { "ACCEPT-LANGUAGE", "fr" }
            });

            // Act
            var section = controller.Get(1, 1, 2);
            var field   = section.Fields.First();

            // Assert
            Assert.AreEqual("Section fr", section.Label);
            Assert.IsNull(section.Labels);
            Assert.AreEqual("Field fr", field.Label);
            Assert.IsNull(field.Labels);
        }
        public async Task And_Section_exists_Then_Section_is_returned()
        {
            var applicationId = Guid.NewGuid();
            var sectionId     = Guid.NewGuid();

            var mediator = Substitute.For <IMediator>();

            mediator.Send(Arg.Any <GetSectionRequest>()).Returns(new HandlerResponse <Section>(new Section()
            {
                Id            = sectionId,
                SequenceNo    = 1,
                SectionNo     = 1,
                ApplicationId = applicationId
            }));

            var sectionController = new SectionsController(mediator);

            var result = await sectionController.GetSection(applicationId, sectionId);

            result.Value.Should().BeOfType <Section>();
            result.Value.Id.Should().Be(sectionId);
        }
예제 #17
0
        public async Task GetAllSections_ReturnsSections()
        {
            var client = Factory.CreateClient();

            var section1 = new Section
            {
                SectionString = "Section 1",
                Instructor    = new Instructor {
                    FirstName = "Tom", LastName = "Capaul"
                }
            };
            var section2 = new Section
            {
                SectionString = "Section 2",
                InstructorId  = 1
            };

            var service = new Mock <ISectionService>();
            //service.Setup(x => x.GetAllSections())
            //    .Returns(Task.FromResult(new Collection<Section> { section1, section2 }))
            //    .Verifiable();


            var controller = new SectionsController(service.Object, Mapper.Instance);
            await controller.AddSection(Mapper.Map <SectionInputViewModel>(section1));

            await controller.AddSection(Mapper.Map <SectionInputViewModel>(section2));

            var result = (await controller.GetAllSections()).Result as OkObjectResult;

            List <SectionViewModel> sections = ((IEnumerable <SectionViewModel>)result.Value).ToList();

            Assert.AreEqual(2, sections.Count);
            AssertAreEqual(sections[0], section1);
            AssertAreEqual(sections[1], section2);
            service.VerifyAll();
        }
예제 #18
0
        public SectionsControllerTest(ApplicationDbContextFixture contextFixture)
        {
            Context     = contextFixture.DbContext;
            RoleManager = contextFixture.RoleManager;
            UserManager = contextFixture.UserManager;

            Moderador     = contextFixture.Moderador;
            Cliente       = contextFixture.Cliente;
            Prestador     = contextFixture.Prestador;
            Administrador = contextFixture.Administrador;

            ModeradorLog     = contextFixture.ModeradorLog;
            ClientLog        = contextFixture.ClientLog;
            PrestadorLog     = contextFixture.PrestadorLog;
            AdministradorLog = contextFixture.AdministradorLog;

            ClienteRole       = contextFixture.ClienteRole;
            ModeradoresRole   = contextFixture.ModeradoresRole;
            PrestadorRole     = contextFixture.PrestadorRole;
            AdministradorRole = contextFixture.AdministradorRole;

            Controller           = new SectionsController(Context, UserManager);
            UserManualController = new UserManualsController(Context, UserManager);
        }
 public void SetUp()
 {
     sectionFactory_Mock = new SectionFactory_Mock();
     controller          = new SectionsController(sectionFactory_Mock, null);
 }
예제 #20
0
        public void TestFields()
        {
            // Arrange
            var controller = new SectionsController(InitRepo());

            // Act
            var section = controller.Get(1, 1, 1, 1);

            // Asserts
            var field = section.Fields.ElementAt(0);

            Assert.IsTrue(field is TextField);
            Assert.IsTrue(((TextField)field).SubType is TextType.TextField);
            Assert.AreEqual("Textbox Test", ((TextField)field).Value);
            Assert.AreEqual(2000, ((TextField)field).MaxLength);

            field = section.Fields.ElementAt(1);
            Assert.IsTrue(field is TextField);
            Assert.IsTrue(((TextField)field).SubType is TextType.Password);
            Assert.AreEqual(2000, ((TextField)field).MaxLength);

            field = section.Fields.ElementAt(2);
            Assert.IsTrue(field is TextField);
            Assert.IsTrue(((TextField)field).SubType is TextType.Email);
            Assert.AreEqual(2000, ((TextField)field).MaxLength);

            field = section.Fields.ElementAt(3);
            Assert.IsTrue(field is TextField);
            Assert.IsTrue(((TextField)field).SubType is TextType.Color);
            Assert.AreEqual(2000, ((TextField)field).MaxLength);

            field = section.Fields.ElementAt(4);
            Assert.IsTrue(field is TextField);
            Assert.IsTrue(((TextField)field).SubType is TextType.Telephone);
            Assert.AreEqual(2000, ((TextField)field).MaxLength);

            field = section.Fields.ElementAt(5);
            Assert.IsTrue(field is NumberField);

            field = section.Fields.ElementAt(6);
            Assert.IsTrue(field is DateField);

            field = section.Fields.ElementAt(7);
            Assert.IsTrue(field is TextAreaField);
            Assert.IsTrue(((TextAreaField)field).SubType is TextAreaType.TextArea);
            Assert.AreEqual(2000, ((TextAreaField)field).MaxLength);
            Assert.AreEqual(10, ((TextAreaField)field).Rows);

            field = section.Fields.ElementAt(8);
            Assert.IsTrue(field is TextAreaField);
            Assert.IsTrue(((TextAreaField)field).SubType is TextAreaType.TinyMce);
            Assert.AreEqual(2000, ((TextAreaField)field).MaxLength);
            Assert.AreEqual(10, ((TextAreaField)field).Rows);

            field = section.Fields.ElementAt(9);
            Assert.IsTrue(field is TextAreaField);
            Assert.IsTrue(((TextAreaField)field).SubType is TextAreaType.Quill);
            Assert.AreEqual(2000, ((TextAreaField)field).MaxLength);
            Assert.AreEqual(10, ((TextAreaField)field).Rows);

            field = section.Fields.ElementAt(10);
            Assert.IsTrue(field is SelectField);
            Assert.AreEqual(3, ((SelectField)field).Values.Count);
            Assert.AreEqual(1, ((SelectField)field).Values.Count(v => v.IsSelected));
            Assert.AreEqual("2", ((SelectField)field).Values.First(v => v.IsSelected).Value);

            field = section.Fields.ElementAt(11);
            Assert.IsTrue(field is RadioGroupField);
            Assert.AreEqual(3, ((RadioGroupField)field).Values.Count);

            field = section.Fields.ElementAt(12);
            Assert.IsTrue(field is CheckboxGroupField);
            Assert.AreEqual(3, ((CheckboxGroupField)field).Values.Count);
            Assert.AreEqual(2, ((CheckboxGroupField)field).Values.Count(v => v.IsSelected));
            Assert.AreEqual("1", ((CheckboxGroupField)field).Values.First(v => v.IsSelected).Value);
            Assert.AreEqual("3", ((CheckboxGroupField)field).Values.Last(v => v.IsSelected).Value);

            field = section.Fields.ElementAt(13);
            Assert.IsTrue(field is ParagraphField);
            Assert.IsTrue(((ParagraphField)field).SubType is ParagraphType.P);

            field = section.Fields.ElementAt(14);
            Assert.IsTrue(field is ParagraphField);
            Assert.IsTrue(((ParagraphField)field).SubType is ParagraphType.Address);

            field = section.Fields.ElementAt(15);
            Assert.IsTrue(field is ParagraphField);
            Assert.IsTrue(((ParagraphField)field).SubType is ParagraphType.Blockquote);

            field = section.Fields.ElementAt(16);
            Assert.IsTrue(field is ParagraphField);
            Assert.IsTrue(((ParagraphField)field).SubType is ParagraphType.Canvas);

            field = section.Fields.ElementAt(17);
            Assert.IsTrue(field is ParagraphField);
            Assert.IsTrue(((ParagraphField)field).SubType is ParagraphType.Output);

            field = section.Fields.ElementAt(18);
            Assert.IsTrue(field is HeaderField);
            Assert.IsTrue(((HeaderField)field).SubType is HeaderType.H1);

            field = section.Fields.ElementAt(19);
            Assert.IsTrue(field is HeaderField);
            Assert.IsTrue(((HeaderField)field).SubType is HeaderType.H2);

            field = section.Fields.ElementAt(20);
            Assert.IsTrue(field is HeaderField);
            Assert.IsTrue(((HeaderField)field).SubType is HeaderType.H3);
        }