Exemplo n.º 1
0
        public async Task DeleteApp_SchedulersForAppAreDeleted()
        {
            //arrange
            var app = Application.Create("TestApp", "dev", false);
            await _appApplicationRepository.AddAsync(app);

            var date = new DateTime(2099, 3, 2, 15, 45, 0);

            app.AddDeployEnvironment("QA", false, false, false);
            app.AddFeatureToggle("t1", null, "workItemID1");
            app.AddFeatureToggle("t2", null, "workItemID2");
            await _appApplicationRepository.AddAsync(app);

            var schedule = ToggleSchedule.Create("TestApp", "t1", new[] { "dev" }, true, date, "updatedBy", true);
            await _toggleScheduleRepository.AddAsync(schedule);

            var controller = new ApplicationsController(_appApplicationRepository, _toggleScheduleRepository);

            //act
            await controller.RemoveApp(app.Id);

            //assert
            var schedulers = await _toggleScheduleRepository.GetAllAsync();

            schedulers.Count().Should().Be(0);
        }
        public void GetApplicationModelByIdTest()
        {
            // Arrange
            var mockDependency = new Mock <IApplicationsRepository>();

            mockDependency.Setup(x => x.GetApplicationModelById(1)).Returns(() => new ApplicationModel
            {
                Description = "test",
                Hash        = "#&^Grfefsdf"
            });

            // Act
            var controller = new ApplicationsController()
            {
                ApplicationsRepository = mockDependency.Object
            };

            // Assert
            var res = controller?.GetById(1);

            if (res?.Data != null)
            {
                Assert.AreEqual("test", res.Data.Description);
                Assert.AreEqual("#&^Grfefsdf", res.Data.Hash);
                Assert.AreEqual("OK", res.Description);
            }
            else
            {
                Assert.AreEqual(1, 2);
            }
        }
Exemplo n.º 3
0
        public void EditApp_WithInvalidID_ThrowsInvalidOperationException()
        {
            //arrange
            var app = new Application {
                Id = 1, AppName = "TestApp"
            };

            _context.Applications.Add(app);
            _context.SaveChanges();

            var updatedAppName = "TestAppUpdated";

            var updatedApp = new UpdateApplicationModel
            {
                Id = app.Id++,
                ApplicationName = updatedAppName
            };

            var controller = new ApplicationsController(_context);

            //act
            controller.UpdateApplication(updatedApp);

            //assert
            //throws InvalidOperationException
        }
Exemplo n.º 4
0
        private void registerApplicationButton_Click(object sender, EventArgs e)
        {
            appRegistrationLabel.Text = "";
            var adminController = new ApplicationsController(Properties.Settings.Default);

            string appToken = adminController.RegisterApplication(cprBrokerWebServiceUrlTextBox.Text);

            if (appToken.Length > 0)
            {
                Properties.Settings.Default.AppToken = appToken;
                var  labelText             = "Application is registered.\n";
                var  approveController     = new ApplicationsController(Properties.Settings.Default);
                bool applicationIsApproved = approveController.ApproveApplication(cprBrokerWebServiceUrlTextBox.Text,
                                                                                  adminAppTokenTextBox.Text);
                if (applicationIsApproved)
                {
                    labelText += "Application is approved.\n";
                    appRegistrationLabel.Text = labelText
                                                + "Application Token: " + appToken;
                }
                else
                {
                    labelText += "Application is NOT approved.\n"
                                 + "You need to manually approve it on: "
                                 + GetApplicationsUrl();
                }
                appRegistrationLabel.Text = labelText;
            }
            else
            {
                appRegistrationLabel.Text = "Registration did not succeed. Please see the weblog for CPR Broker: "
                                            + GetWebLogUrl();
            }
        }
Exemplo n.º 5
0
        private void VerifyRegistrationAndApproval()
        {
            var adminController         = new ApplicationsController(Properties.Settings.Default);
            var applicationRegistration = adminController.ApplicationIsRegistered(cprBrokerWebServiceUrlTextBox.Text);

            if (applicationRegistration != null)
            {
                appRegistrationLabel.Text = "Application is registered.\n";
                string approveLabelText = "";
                if (applicationRegistration.IsApproved)
                {
                    approveLabelText = "Application is approved";
                    Properties.Settings.Default.AppToken = applicationRegistration.Token;
                }
                else
                {
                    approveLabelText = "Application is NOT approved.\n"
                                       + "You need to manually approve it on: "
                                       + GetApplicationsUrl();
                }
                appRegistrationLabel.Text += approveLabelText
                                             + "\n"
                                             + "Application Token: " + Properties.Settings.Default.AppToken;
            }
        }
 public ReportViewModel(ReportsController controller, ApplicationsController applicationsController, IAppNavigationService navigationService)
 {
     ApplicationsController = applicationsController;
     _controller            = controller;
     _navigationService     = navigationService;
     Messenger.Register <ReportMessage>(this, OnNewReport);
 }
Exemplo n.º 7
0
        public async Task TestingEvaluateApplicationSuccessfull()
        {
            InitializeDatabaseWithDataTest();
            ApplicationsController controller = new ApplicationsController(_context);
            // Act
            Application appTest      = _context.Applications.SingleOrDefault(a => a.ApplicationId == 1);
            Application appModelTest = new Application
            {
                ApplicationId        = appTest.ApplicationId,
                StudentId            = _context.Students.Where(s => s.UserFullname.Equals("Teste User 1")).FirstOrDefault().Id,
                ApplicationStatId    = 3,
                BilateralProtocol1Id = 2,
                BilateralProtocol2Id = 6,
                BilateralProtocol3Id = 10,
                EmployeeId           = _context.Employees.Where(s => s.UserFullname.Equals("Empregado Teste")).FirstOrDefault().Id,
                CreationDate         = new DateTime(2017, 11, 13),
                ArithmeticMean       = 15.0,
                ECTS             = 66,
                MotivationLetter = 15.0,
                Interview        = 15.0,
                FinalGrade       = 15.0
            };
            var result = await controller.Edit(appTest.ApplicationId, appModelTest);

            _context.Entry(appTest).State = EntityState.Detached;
            appTest = _context.Applications.SingleOrDefault(a => a.ApplicationId == 1);
            Assert.Equal(15, appTest.FinalGrade);
        }
Exemplo n.º 8
0
        public void EditApp_AppIsBeingModified()
        {
            //arrange
            var app = new Application {
                Id = 1, AppName = "TestApp"
            };

            _context.Applications.Add(app);
            _context.SaveChanges();

            var updatedAppName = "TestAppUpdated";

            var updatedApp = new UpdateApplicationModel
            {
                Id = app.Id,
                ApplicationName = updatedAppName
            };

            var controller = new ApplicationsController(_context);

            //act
            var result = controller.UpdateApplication(updatedApp);

            //assert
            result.Should().BeOfType <OkResult>();
            app.AppName.Should().Be(updatedAppName);
        }
        public async Task Then_Gets_Applications_From_Mediator(GetApplicationsQueryResult queryResult, [Frozen] Mock <IMediator> mediator,
                                                               [Greedy] ApplicationsController controller)
        {
            mediator.Setup(o => o.Send(It.IsAny <GetApplicationsQuery>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(queryResult);

            var controllerResult = await controller.GetApplications(1) as OkObjectResult;

            var result = controllerResult.Value as GetApplicationsResponse;

            Assert.IsNotNull(controllerResult);
            Assert.IsNotNull(result);

            var expected = (GetApplicationsResponse)queryResult;
            var x        = expected.Applications.First();
            var y        = result.Applications.First();

            Assert.AreEqual(expected.Applications.Count(), result.Applications.Count());
            Assert.AreEqual(x.DasAccountName, y.DasAccountName);
            Assert.AreEqual(x.Details, y.Details);
            Assert.AreEqual(x.Amount, y.Amount);
            Assert.AreEqual(x.Status, y.Status);
            Assert.AreEqual(x.CreatedOn, y.CreatedOn);
            Assert.AreEqual(x.NumberOfApprentices, y.NumberOfApprentices);
            Assert.AreEqual(x.Id, y.Id);
            Assert.AreEqual(x.PledgeId, y.PledgeId);
            Assert.AreEqual(x.IsNamePublic, y.IsNamePublic);
        }
Exemplo n.º 10
0
        public async Task Index()
        {
            var app = new Application()
            {
                Id        = Guid.NewGuid(),
                Name      = "1",
                ColourHex = "#FFFFFF"
            };

            var items = new List <Application>()
            {
                app
            };

            var service = new Mock <IApplicationService>();

            service.Setup(c => c.GetApplications())
            .ReturnsAsync(items);

            var controller = new ApplicationsController(service.Object);

            var result = await controller.Index();

            var okResult    = Assert.IsType <OkObjectResult>(result);
            var returnValue = Assert.IsType <List <Application> >(okResult.Value);

            Assert.Same(items, returnValue);
        }
Exemplo n.º 11
0
        public void SetController(IController controller)
        {
            _controller = (ApplicationsController)controller;

            _controller.ApplicationsChanged += _OnApplicationsChanged;

            FillData();
        }
Exemplo n.º 12
0
        public async Task TestingSeriationSuccessfull()
        {
            InitializeDatabaseWithDataTest();
            ApplicationsController controller = new ApplicationsController(_context);
            // Act
            await controller.Seriation();

            // Assert
            Assert.Equal(0, _context.Applications.Count(a => a.ApplicationStatId == 3));
        }
Exemplo n.º 13
0
        public void Controller_Applications_Index_Get()
        {
            // Arrange
            ApplicationsController controller = new ApplicationsController();

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

            // Assert
            Assert.IsNotNull(result);
        }
Exemplo n.º 14
0
        private bool TestBrokerUrl()
        {
            var  adminController = new ApplicationsController(Properties.Settings.Default);
            bool testOk          = adminController.TestWSConnection(cprBrokerWebServiceUrlTextBox.Text);

            if (!testOk)
            {
                MessageBox.Show(this, "Connection failed. The CPR Broker Web Service URL is incorrect or the service is unavailable", "Connection failure", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(testOk);
        }
Exemplo n.º 15
0
        public async Task TestingAssignEmployeeFailed()
        {
            ApplicationsController controller = new ApplicationsController(_context);
            // Act
            String employeeId1 = _context.Employees.SingleOrDefault(a => a.UserFullname.Equals("Empregado Teste1")).Id;
            String employeeId2 = _context.Employees.SingleOrDefault(a => a.UserFullname.Equals("Empregado Teste")).Id;
            await controller.AssignEmployee(employeeId1, 1);

            // Assert

            Assert.Equal(employeeId2, _context.Applications.First().EmployeeId);
        }
Exemplo n.º 16
0
        public void Controller_Applications_Details_Get()
        {
            // Arrange
            ApplicationsController controller = new ApplicationsController();
            int id = 2;

            // Act
            ViewResult result = controller.Details(id) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Exemplo n.º 17
0
        public void Setup()
        {
            _pledgeId = _fixture.Create <int>();

            _mediator = new Mock <IMediator>();

            _queryResult = _fixture.Create <GetApplicationsQueryResult>();
            _mediator.Setup(x => x.Send(It.Is <GetApplicationsQuery>(q => q.PledgeId == _pledgeId), CancellationToken.None))
            .ReturnsAsync(_queryResult);

            _controller = new ApplicationsController(_mediator.Object);
        }
Exemplo n.º 18
0
        public async Task AddApplication_ReturnBadRequestResult_WhenModelStateIsInvalid()
        {
            //arrange
            var controller = new ApplicationsController(_appApplicationRepository, _toggleScheduleRepository);

            controller.ModelState.AddModelError("error", "some error");

            //act
            var result = await controller.AddApplication(new AddApplicationModel());

            //assert
            result.Should().BeOfType <BadRequestObjectResult>().Which.Should().NotBeNull();
        }
Exemplo n.º 19
0
        private void GetServiceInfoButton_Click(object sender, EventArgs e)
        {
            var adminController = new ApplicationsController(Properties.Settings.Default);
            var capabilities    = adminController.GetCapabillities();

            InfoText.Text = "";
            foreach (var capability in capabilities)
            {
                InfoText.Text += "Version: " + capability.Version + "\r\n"
                                 + "Details: " + capability.Details + "\r\n"
                                 + "Functions: " + String.Join("\r\n", capability.Functions.ToArray()) + "\r\n";
            }
        }
Exemplo n.º 20
0
 protected override void Run()
 {
     try
     {
         var applicationsDialog        = new ApplicationsDialog();
         var samplesImporterController = new ApplicationsController(applicationsDialog);
         applicationsDialog.Run(Xwt.MessageDialog.RootWindow);
     }
     catch (Exception ex)
     {
         MessageService.ShowError(ex.Message);
     }
 }
Exemplo n.º 21
0
        public async Task TestingSeriationNotSuccessfull()
        {
            ApplicationsController controller = new ApplicationsController(_context);

            // Act
            _context.Applications.First().ApplicationStatId = 1;
            _context.SaveChanges();
            var result = await controller.Seriation();

            // Assert

            Assert.Equal(1, _context.Applications.Count(a => a.ApplicationStatId == 3));
        }
Exemplo n.º 22
0
        public void AddApplication_ReturnBadRequestResult_WhenModelStateIsInvalid()
        {
            //arrange
            var controller = new ApplicationsController(_context);

            controller.ModelState.AddModelError("error", "some error");

            //act
            var result = controller.AddApplication(new AddApplicationModel());

            //assert
            result.Should().BeOfType <BadRequestObjectResult>().Which.Should().NotBeNull();
        }
Exemplo n.º 23
0
        public void DeleteApp_AppIsDeleted_EnvironmentsFeatureTogglesAndStatusesAreDeleted()
        {
            //arrange
            var app = new Application {
                Id = 1, AppName = "TestApp"
            };

            var environment = new DeployEnvironment {
                Application = app, ApplicationId = app.Id, EnvName = "TestEnv"
            };
            var environment2 = new DeployEnvironment {
                Application = app, ApplicationId = app.Id, EnvName = "TestEnv2"
            };
            var environment3 = new DeployEnvironment {
                Application = app, ApplicationId = app.Id, EnvName = "TestEnv3"
            };

            var featureStatus1 = new FeatureToggleStatus {
                Enabled = false, Id = 1, IsDeployed = false, Environment = environment, EnvironmentId = environment.Id
            };
            var featureStatus2 = new FeatureToggleStatus {
                Enabled = false, Id = 2, IsDeployed = false, Environment = environment2, EnvironmentId = environment2.Id
            };
            var featureStatus3 = new FeatureToggleStatus {
                Enabled = false, Id = 3, IsDeployed = false, Environment = environment3, EnvironmentId = environment3.Id
            };

            var feature = new FeatureToggle {
                Id = 1, Application = app, ApplicationId = app.Id, FeatureToggleStatuses = new List <FeatureToggleStatus> {
                    featureStatus1, featureStatus2, featureStatus3
                }, ToggleName = "Test"
            };

            _context.FeatureToggleStatuses.AddRange(featureStatus1, featureStatus2, featureStatus3);
            _context.Applications.Add(app);
            _context.DeployEnvironments.AddRange(environment, environment2, environment3);
            _context.FeatureToggles.Add(feature);
            _context.SaveChanges();

            var controller = new ApplicationsController(_context);

            //act
            var result = controller.RemoveApp(app.Id);

            //assert
            result.Should().BeOfType <OkResult>();
            _context.Applications.Count().Should().Be(0);
            _context.FeatureToggles.Count().Should().Be(0);
            _context.DeployEnvironments.Count().Should().Be(0);
            _context.FeatureToggleStatuses.Count().Should().Be(0);
        }
Exemplo n.º 24
0
        public async Task DeleteApp_WithInvalidID_ThrowsInvalidOperationException()
        {
            //arrange
            var app = Application.Create("TestApp", "dev", false);
            await _appApplicationRepository.AddAsync(app);

            var controller = new ApplicationsController(_appApplicationRepository, _toggleScheduleRepository);

            //act
            await controller.RemoveApp(Guid.NewGuid());

            //assert
            //throws InvalidOperationException
        }
Exemplo n.º 25
0
        public async Task TestingNoFilter()
        {
            ApplicationsController controller = new ApplicationsController(_context);
            // Act
            String employeeId = _context.Employees.SingleOrDefault(a => a.UserFullname.Equals("Empregado Teste")).Id;
            var    result     = await controller.Filter("", employeeId);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <IEnumerable <Application> >(
                viewResult.ViewData.Model);

            Assert.Equal(2, model.Count());
        }
Exemplo n.º 26
0
        public async Task TestingAssignEmployeeSuccessfull()
        {
            ApplicationsController controller = new ApplicationsController(_context);

            // Act
            _context.Applications.First().EmployeeId = null;
            _context.SaveChanges();
            String employeeId = _context.Employees.SingleOrDefault(a => a.UserFullname.Equals("Empregado Teste")).Id;
            await controller.AssignEmployee(employeeId, 1);

            // Assert

            Assert.Equal(employeeId, _context.Applications.First().EmployeeId);
        }
Exemplo n.º 27
0
        public async Task TestingDisplaySeriationBeforeSeriation()
        {
            InitializeDatabaseWithDataTest();
            ApplicationsController controller = new ApplicationsController(_context);
            // Act
            var result = await controller.DisplaySeriation();

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <IEnumerable <Application> >(
                viewResult.ViewData.Model);

            Assert.Empty(model);
        }
Exemplo n.º 28
0
        public async Task TestingApplicationHistory()
        {
            ApplicationsController controller = new ApplicationsController(_context);
            // Act
            String studentId = _context.Students.Where(s => s.UserFullname.Equals("Teste User 1")).FirstOrDefault().Id;
            var    result    = await controller.ApplicationHistory(studentId);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <IEnumerable <ApplicationStatHistory> >(
                viewResult.ViewData.Model);

            Assert.Equal(2, model.Count());
        }
            public void IsValidAppId_SuccessfullyIdentifiesValidAndInvalidAppIdValues()
            {
                ApplicationsController appController = new ApplicationsController(null, null);

                Assert.True(appController.IsValidAppId("test/a234"));
                Assert.True(appController.IsValidAppId("sp1/ab23"));
                Assert.True(appController.IsValidAppId("multipledash/a-b-234"));

                Assert.False(appController.IsValidAppId("2orgstartswithnumber/b234"));
                Assert.False(appController.IsValidAppId("UpperCaseOrg/x234"));
                Assert.False(appController.IsValidAppId("org-with-dash/x234"));
                Assert.False(appController.IsValidAppId("morethanoneslash/a2/34"));
                Assert.False(appController.IsValidAppId("test/UpperCaseApp"));
                Assert.False(appController.IsValidAppId("testonlynumbersinapp/42"));
            }
Exemplo n.º 30
0
        public void AddApplication_ApplicationIsBeingAdded()
        {
            //arrange
            var appModel = new AddApplicationModel {
                ApplicationName = "BCC"
            };

            var controller = new ApplicationsController(_context);

            //act
            controller.AddApplication(appModel);

            //assert
            _context.Applications.FirstOrDefault().AppName.Should().Be(appModel.ApplicationName);
        }