public void AdverseEventsAnalytics_View(bool async, string viewName)
            {
                //Arrange
                var vRepository = new Mock<IVisitRepository>();
                var dfdRepository = new Mock<IDemographicFormDataRepository>();
                var aefdRepository = new Mock<IAdverseEventFormDataRepository>();
                var controller = new AnalyticsController(null, vRepository.Object, dfdRepository.Object, null, aefdRepository.Object,
                                                         null);
                vRepository.Setup(r => r.GetAeAnalyticsData()).Returns(new List<AeAnalyticsDto>());

                EmulateControllerContext(controller, async);

                //Act
                var result = controller.AdverseEvents();

                //Assert
                Assert.That(result, Is.Not.Null);
                Assert.That(result is ViewResultBase);
                var viewResultBase = result as ViewResultBase;
                Assert.That(viewResultBase.Model, Is.Not.Null);
                Assert.That(viewResultBase.ViewName, Is.EqualTo(viewName));
            }
            public void AdverseEvents_ComplexTest()
            {
                //Arrange
                var vRepository = new Mock<IVisitRepository>();
                var dfdRepository = new Mock<IDemographicFormDataRepository>();
                var aefdRepository = new Mock<IAdverseEventFormDataRepository>();
                var controller = new AnalyticsController(null, vRepository.Object, dfdRepository.Object, null, aefdRepository.Object,
                                                         null);

                var dtos = new List<AeAnalyticsDto> {
                    CreateAeAnalyticsDto("Clinic1", "Super", "Doctor", 100, 200),
                    CreateAeAnalyticsDto("Clinic1", "Super", "Doctor", 101, 201),
                    CreateAeAnalyticsDto("Clinic1", "Super", "Doctor", 102, 202),
                    CreateAeAnalyticsDto("Clinic2", "Super1", "Doctor1", 103, 203),
                    CreateAeAnalyticsDto("Clinic2", "Super1", "Doctor1", 104, 204),
                    CreateAeAnalyticsDto("Clinic2", "Super1", "Doctor1", 105, 205),
                    CreateAeAnalyticsDto("Clinic2", "Super2", "Doctor2", 106, 206),
                    CreateAeAnalyticsDto("Clinic1", "Super", "Doctor", 107, 207),
                    CreateAeAnalyticsDto("Clinic1", "Super4", "Doctor4", 108, 208),
                    CreateAeAnalyticsDto("Clinic1", "Super4", "Doctor4", 109, 209),
                    CreateAeAnalyticsDto("Clinic3", "Super5", "Doctor5", 110, 210),
                    CreateAeAnalyticsDto("Clinic3", "Super6", "Doctor6", 111, 211),
                    CreateAeAnalyticsDto("Clinic3", "Super7", "Doctor7", 112, 212)
                };

                vRepository.Setup(r => r.GetAeAnalyticsData()).Returns(new List<AeAnalyticsDto>(dtos));

                var formD1 = CreateTestCrf(FormType.Demographics, 100, (int) Race.Asian, (int) Gender.Male);
                var formD2 = CreateTestCrf(FormType.Demographics, 101, (int) Race.Asian, (int) Gender.Female);
                var formD3 = CreateTestCrf(FormType.Demographics, 102, (int) Race.Asian, (int) Gender.Female);
                var formD4 = CreateTestCrf(FormType.Demographics, 103, (int) Race.Asian, (int) Gender.Male);
                var formD5 = CreateTestCrf(FormType.Demographics, 104, (int) Race.Asian, (int) Gender.Female);
                var formD6 = CreateTestCrf(FormType.Demographics, 105, (int) Race.Asian, (int) Gender.Female);
                var formD7 = CreateTestCrf(FormType.Demographics, 106, (int) Race.HispanicLatino, (int) Gender.Female);
                var formD8 = CreateTestCrf(FormType.Demographics, 107, (int) Race.HispanicLatino, (int) Gender.Male);
                var formD9 = CreateTestCrf(FormType.Demographics, 108, (int) Race.White, (int) Gender.Female);
                var formD10 = CreateTestCrf(FormType.Demographics, 109, (int) Race.White, (int) Gender.Male);
                var formD11 = CreateTestCrf(FormType.Demographics, 110, (int) Race.AfricanAmerican, (int) Gender.Male);
                var formD12 = CreateTestCrf(FormType.Demographics, 111, (int) Race.AfricanAmerican, (int) Gender.Female);
                var formD13 = CreateTestCrf(FormType.Demographics, 112, (int) Race.AmericanIndian, (int) Gender.Male);

                var formAe1 = CreateTestCrf(FormType.AdverseEvent, 200, (int) AdverseEventIntensity.Moderate,
                                            (int) AdverseEventRelanshionship.Suspected);
                var formAe2 = CreateTestCrf(FormType.AdverseEvent, 201, (int) AdverseEventIntensity.Moderate,
                                            (int) AdverseEventRelanshionship.NotRelated);
                var formAe3 = CreateTestCrf(FormType.AdverseEvent, 202, (int) AdverseEventIntensity.Moderate,
                                            (int) AdverseEventRelanshionship.NotRelated);
                var formAe4 = CreateTestCrf(FormType.AdverseEvent, 203, (int) AdverseEventIntensity.Mild,
                                            (int) AdverseEventRelanshionship.Suspected);
                var formAe5 = CreateTestCrf(FormType.AdverseEvent, 204, (int) AdverseEventIntensity.Moderate,
                                            (int) AdverseEventRelanshionship.Unlikely);
                var formAe6 = CreateTestCrf(FormType.AdverseEvent, 205, (int) AdverseEventIntensity.Moderate,
                                            (int) AdverseEventRelanshionship.Unlikely);
                var formAe7 = CreateTestCrf(FormType.AdverseEvent, 206, (int) AdverseEventIntensity.Mild,
                                            (int) AdverseEventRelanshionship.NotRelated);
                var formAe8 = CreateTestCrf(FormType.AdverseEvent, 207, (int) AdverseEventIntensity.Moderate,
                                            (int) AdverseEventRelanshionship.NotRelated);
                var formAe9 = CreateTestCrf(FormType.AdverseEvent, 208, (int) AdverseEventIntensity.Severe,
                                            (int) AdverseEventRelanshionship.Suspected);
                var formAe10 = CreateTestCrf(FormType.AdverseEvent, 209, (int) AdverseEventIntensity.Mild,
                                             (int) AdverseEventRelanshionship.Probable);
                var formAe11 = CreateTestCrf(FormType.AdverseEvent, 210, (int) AdverseEventIntensity.Mild,
                                             (int) AdverseEventRelanshionship.Suspected);
                var formAe12 = CreateTestCrf(FormType.AdverseEvent, 211, (int) AdverseEventIntensity.Severe,
                                             (int) AdverseEventRelanshionship.Probable);
                var formAe13 = CreateTestCrf(FormType.AdverseEvent, 212, (int) AdverseEventIntensity.Moderate,
                                             (int) AdverseEventRelanshionship.NotRelated);

                dfdRepository.Setup(r => r.GetFormDataByFormId(formD1.Id)).Returns(formD1 as DemographicFormData);
                dfdRepository.Setup(r => r.GetFormDataByFormId(formD2.Id)).Returns(formD2 as DemographicFormData);
                dfdRepository.Setup(r => r.GetFormDataByFormId(formD3.Id)).Returns(formD3 as DemographicFormData);
                dfdRepository.Setup(r => r.GetFormDataByFormId(formD4.Id)).Returns(formD4 as DemographicFormData);
                dfdRepository.Setup(r => r.GetFormDataByFormId(formD5.Id)).Returns(formD5 as DemographicFormData);
                dfdRepository.Setup(r => r.GetFormDataByFormId(formD6.Id)).Returns(formD6 as DemographicFormData);
                dfdRepository.Setup(r => r.GetFormDataByFormId(formD7.Id)).Returns(formD7 as DemographicFormData);
                dfdRepository.Setup(r => r.GetFormDataByFormId(formD8.Id)).Returns(formD8 as DemographicFormData);
                dfdRepository.Setup(r => r.GetFormDataByFormId(formD9.Id)).Returns(formD9 as DemographicFormData);
                dfdRepository.Setup(r => r.GetFormDataByFormId(formD10.Id)).Returns(formD10 as DemographicFormData);
                dfdRepository.Setup(r => r.GetFormDataByFormId(formD11.Id)).Returns(formD11 as DemographicFormData);
                dfdRepository.Setup(r => r.GetFormDataByFormId(formD12.Id)).Returns(formD12 as DemographicFormData);
                dfdRepository.Setup(r => r.GetFormDataByFormId(formD13.Id)).Returns(formD13 as DemographicFormData);

                aefdRepository.Setup(r => r.GetFormDataByFormId(formAe1.Id)).Returns(formAe1 as AdverseEventFormData);
                aefdRepository.Setup(r => r.GetFormDataByFormId(formAe2.Id)).Returns(formAe2 as AdverseEventFormData);
                aefdRepository.Setup(r => r.GetFormDataByFormId(formAe3.Id)).Returns(formAe3 as AdverseEventFormData);
                aefdRepository.Setup(r => r.GetFormDataByFormId(formAe4.Id)).Returns(formAe4 as AdverseEventFormData);
                aefdRepository.Setup(r => r.GetFormDataByFormId(formAe5.Id)).Returns(formAe5 as AdverseEventFormData);
                aefdRepository.Setup(r => r.GetFormDataByFormId(formAe6.Id)).Returns(formAe6 as AdverseEventFormData);
                aefdRepository.Setup(r => r.GetFormDataByFormId(formAe7.Id)).Returns(formAe7 as AdverseEventFormData);
                aefdRepository.Setup(r => r.GetFormDataByFormId(formAe8.Id)).Returns(formAe8 as AdverseEventFormData);
                aefdRepository.Setup(r => r.GetFormDataByFormId(formAe9.Id)).Returns(formAe9 as AdverseEventFormData);
                aefdRepository.Setup(r => r.GetFormDataByFormId(formAe10.Id)).Returns(formAe10 as AdverseEventFormData);
                aefdRepository.Setup(r => r.GetFormDataByFormId(formAe11.Id)).Returns(formAe11 as AdverseEventFormData);
                aefdRepository.Setup(r => r.GetFormDataByFormId(formAe12.Id)).Returns(formAe12 as AdverseEventFormData);
                aefdRepository.Setup(r => r.GetFormDataByFormId(formAe13.Id)).Returns(formAe13 as AdverseEventFormData);

                EmulateControllerContext(controller, false);

                //Act
                var result = controller.AdverseEvents();

                //Assert
                Assert.That(result, Is.Not.Null);
                Assert.That(result is ViewResultBase);
                var viewResultBase = result as ViewResultBase;
                Assert.That(viewResultBase.Model, Is.Not.Null);
                Assert.That(viewResultBase.Model is List<AdverseEventsAnalyticsViewModel>);
                var model = viewResultBase.Model as List<AdverseEventsAnalyticsViewModel>;
                Assert.That(model.Count, Is.EqualTo(11));

                AssertAdverseEventsAnalyticsViewModel(model[0], "Clinic1", "Super Doctor", Race.Asian, Gender.Male,
                                                      AdverseEventIntensity.Moderate, AdverseEventRelanshionship.Suspected, 1,
                                                      vRepository);
                AssertAdverseEventsAnalyticsViewModel(model[1], "Clinic1", "Super Doctor", Race.Asian, Gender.Female,
                                                      AdverseEventIntensity.Moderate, AdverseEventRelanshionship.NotRelated, 2,
                                                      vRepository);
                AssertAdverseEventsAnalyticsViewModel(model[2], "Clinic2", "Super1 Doctor1", Race.Asian, Gender.Male,
                                                      AdverseEventIntensity.Mild, AdverseEventRelanshionship.Suspected, 1,
                                                      vRepository);
                AssertAdverseEventsAnalyticsViewModel(model[3], "Clinic2", "Super1 Doctor1", Race.Asian, Gender.Female,
                                                      AdverseEventIntensity.Moderate, AdverseEventRelanshionship.Unlikely, 2,
                                                      vRepository);
                AssertAdverseEventsAnalyticsViewModel(model[4], "Clinic2", "Super2 Doctor2", Race.HispanicLatino, Gender.Female,
                                                      AdverseEventIntensity.Mild, AdverseEventRelanshionship.NotRelated, 1,
                                                      vRepository);
                AssertAdverseEventsAnalyticsViewModel(model[5], "Clinic1", "Super Doctor", Race.HispanicLatino, Gender.Male,
                                                      AdverseEventIntensity.Moderate, AdverseEventRelanshionship.NotRelated, 1,
                                                      vRepository);
                AssertAdverseEventsAnalyticsViewModel(model[6], "Clinic1", "Super4 Doctor4", Race.White, Gender.Female,
                                                      AdverseEventIntensity.Severe, AdverseEventRelanshionship.Suspected, 1,
                                                      vRepository);
                AssertAdverseEventsAnalyticsViewModel(model[7], "Clinic1", "Super4 Doctor4", Race.White, Gender.Male,
                                                      AdverseEventIntensity.Mild, AdverseEventRelanshionship.Probable, 1,
                                                      vRepository);
                AssertAdverseEventsAnalyticsViewModel(model[8], "Clinic3", "Super5 Doctor5", Race.AfricanAmerican, Gender.Male,
                                                      AdverseEventIntensity.Mild, AdverseEventRelanshionship.Suspected, 1,
                                                      vRepository);
                AssertAdverseEventsAnalyticsViewModel(model[9], "Clinic3", "Super6 Doctor6", Race.AfricanAmerican, Gender.Female,
                                                      AdverseEventIntensity.Severe, AdverseEventRelanshionship.Probable, 1,
                                                      vRepository);
                AssertAdverseEventsAnalyticsViewModel(model[10], "Clinic3", "Super7 Doctor7", Race.AmericanIndian, Gender.Male,
                                                      AdverseEventIntensity.Moderate, AdverseEventRelanshionship.NotRelated, 1,
                                                      vRepository);
            }
            public void AdverseEvents_CorrectViewModel_Mapping()
            {
                //Arrange
                var vRepository = new Mock<IVisitRepository>();
                var dfdRepository = new Mock<IDemographicFormDataRepository>();
                var aefdRepository = new Mock<IAdverseEventFormDataRepository>();
                var controller = new AnalyticsController(null, vRepository.Object, dfdRepository.Object, null, aefdRepository.Object,
                                                         null);
                var demogForm =
                    CreateTestCrf(FormType.Demographics, 111, (int) Race.Asian, (int) Gender.Female) as DemographicFormData;
                var aeForm =
                    CreateTestCrf(FormType.AdverseEvent, 222, (int) AdverseEventIntensity.Moderate,
                                  (int) AdverseEventRelanshionship.Probable) as AdverseEventFormData;

                var dto = CreateAeAnalyticsDto("Clinic1", "Super", "Doctor", 111, 222);

                vRepository.Setup(r => r.GetAeAnalyticsData()).Returns(new List<AeAnalyticsDto> {dto});
                dfdRepository.Setup(r => r.GetFormDataByFormId(111)).Returns(demogForm);
                aefdRepository.Setup(r => r.GetFormDataByFormId(222)).Returns(aeForm);

                EmulateControllerContext(controller, false);

                //Act
                var result = controller.AdverseEvents();

                //Assert
                Assert.That(result, Is.Not.Null);
                Assert.That(result is ViewResultBase);
                var viewResultBase = result as ViewResultBase;
                Assert.That(viewResultBase.Model, Is.Not.Null);
                Assert.That(viewResultBase.Model is List<AdverseEventsAnalyticsViewModel>);
                var model = viewResultBase.Model as List<AdverseEventsAnalyticsViewModel>;
                Assert.That(model.Count, Is.EqualTo(1));

                AssertAdverseEventsAnalyticsViewModel(model[0], dto.ClinicName, dto.DoctorName, Race.Asian, Gender.Female,
                                                      AdverseEventIntensity.Moderate, AdverseEventRelanshionship.Probable, 1,
                                                      vRepository);
            }
            public void AdverseEvents_CorrectViewModel()
            {
                //Arrange
                var vRepository = new Mock<IVisitRepository>();
                var dfdRepository = new Mock<IDemographicFormDataRepository>();
                var aefdRepository = new Mock<IAdverseEventFormDataRepository>();
                var controller = new AnalyticsController(null, vRepository.Object, dfdRepository.Object, null, aefdRepository.Object,
                                                         null);
                vRepository.Setup(r => r.GetAeAnalyticsData()).Returns(new List<AeAnalyticsDto>());

                EmulateControllerContext(controller, false);

                //Act
                var result = controller.AdverseEvents();

                //Assert
                Assert.That(result, Is.Not.Null);
                Assert.That(result is ViewResultBase);
                var viewResultBase = result as ViewResultBase;
                Assert.That(viewResultBase.Model, Is.Not.Null);
                Assert.That(viewResultBase.Model is List<AdverseEventsAnalyticsViewModel>);
                var model = viewResultBase.Model as List<AdverseEventsAnalyticsViewModel>;
                Assert.That(model.Count, Is.EqualTo(0));

                vRepository.Verify(r => r.GetAeAnalyticsData(), Times.Once());
            }