Exemplo n.º 1
0
 public ConversationModel(string id, string idSubscr, decimal countMin, string rDay, string rNight)
 {
     IDCity             = ValidateController.ConvertStringToInt(id);
     IDSubscriber       = ValidateController.ConvertStringToInt(idSubscr);
     CountMinutes       = Convert.ToInt32(countMin);
     PriceConverstation = CalculationPriceMinutes(rDay, rNight, countMin);
 }
Exemplo n.º 2
0
        private void RegisterAccountClick(object sender, RoutedEventArgs e)
        {
            var cert = new X509Certificate2();

            cert.Import(PathTextBox2.Text);
            if (!ValidateController.ValidateCertificates(cert))
            {
                MessageBox.Show("Certificate is revoked or signed with different CA!");
                return;
            }

            var account =
                AccountsController.GetInstance().AddAccount(new Account(Program.ReadName(cert), PasswordBox2.Password,
                                                                        PathTextBox2.Text));

            if (account)
            {
                AccountsController.GetInstance().SerializeNow();
                MessageBox.Show("You successfully have made an account. Now you can login!");
                Task.Delay(2000);
                Hide();
                _previousWindow.Show();
            }
            else
            {
                MessageBox.Show("Please type all data in text boxes!");
            }

            ;
        }
Exemplo n.º 3
0
        private void Button2_Click(object sender, EventArgs e)
        {
            if (ValidateController.validateItem(labelIDCity.Text))
            {
                sqlConnection = new SqlConnection(con);
                commandString = $@"DELETE FROM [dbo].[City]
									WHERE IdCity = '{labelIDCity.Text}'"                                    ;
                try
                {
                    sqlConnection.Open();
                }
                catch (Exception)
                {
                    MessageBox.Show("Не удалось подключиться");
                }
                command = new SqlCommand(commandString, sqlConnection);
                command.ExecuteNonQuery();
                this.cityTableAdapter.Fill(this.phoneCallDataSet19.City);


                labelIDCity.Text = "";
                ValidateController.CleanerTextBox(textBoxCity);
                ValidateController.CleanerNumeric(numericDiscount, numericRateDay, numericRateNight);
            }
            else
            {
                MessageBox.Show("Выберите строку для удаления");
            }
        }
Exemplo n.º 4
0
        public void TestValidateToken_ValidTrue()
        {
            try
            {
                GenerateController generate = new GenerateController();
                ValidateController validate = new ValidateController();

                // generate a token then validate it
                var generateFunc = new TestDelegate <List <JwtClaim> >(generate.Post);
                var generateTask = Task.Run(() => this.RunTestAsync(generateFunc));
                generateTask.Wait();

                string tokenResult = JsonConvert.DeserializeObject <string>((generateTask.Result as ContentResult).Content);

                Assert.NotNull(tokenResult);

                // token validation part
                var validateFunc = new TestDelegate <string>(validate.Post);
                var validateTask = Task.Run(() => this.RunTestAsync(validateFunc, JsonConvert.SerializeObject(tokenResult)));
                validateTask.Wait();

                var result    = validateTask.Result as ContentResult;
                var validated = JsonConvert.DeserializeObject <bool>((validateTask.Result as ContentResult).Content);

                Assert.True(validated);
            }
            catch (Exception e)
            {
                m_logger.WriteLine(e.Message);
                Assert.Null(e);
            }
        }
Exemplo n.º 5
0
        private void Button2_Click(object sender, EventArgs e)
        {
            if (ValidateController.validateItem(idSubscriber.Text))
            {
                sqlConnection = new SqlConnection(con);
                commandString = $@"DELETE FROM [dbo].[Subscribers]
									WHERE IdSubscriber = '{idSubscriber.Text}'"                                    ;
                try
                {
                    sqlConnection.Open();
                }
                catch (Exception)
                {
                    MessageBox.Show("Не удалось подключиться");
                }
                command = new SqlCommand(commandString, sqlConnection);
                command.ExecuteNonQuery();
                this.subscribersTableAdapter2.Fill(this.phoneCallDataSet15.Subscribers);

                idSubscriber.Text = "";
                ValidateController.CleanerTextBox(textBoxAddress, textBoxInn, textBoxNumber);
                Cursor.Current = Cursors.Default;
            }
            else
            {
                MessageBox.Show("Выберите строку для удаления");
            }
        }
Exemplo n.º 6
0
        public static IEnumerable <object[]> GetValidationFunctions()
        {
            ValidateController validateController = GetController(true);

            yield return(new object[] { new Func <Resource, string, string, Func <System.Threading.Tasks.Task> >((Resource payload, string profile, string mode) => new Func <System.Threading.Tasks.Task>(() => validateController.Validate(payload, profile, mode))) });

            yield return(new object[] { new Func <Resource, string, string, Func <System.Threading.Tasks.Task> >((Resource payload, string profile, string mode) => new Func <System.Threading.Tasks.Task>(() => validateController.ValidateById(payload, profile, mode))) });
        }
Exemplo n.º 7
0
        public bool validate(Label city, Label subscriber, Label minutes)
        {
            bool result = ValidateController.validateItem(IDCity.ToString(), city) &&
                          ValidateController.validateItem(IDSubscriber.ToString(), subscriber) &&
                          ValidateController.validateItem(CountMinutes.ToString(), minutes) &&
                          ValidateController.validateItem(PriceConverstation.ToString());

            return(result);
        }
Exemplo n.º 8
0
        private void Button1_Click(object sender, EventArgs e)
        {
            conversationModel = new ConversationModel(
                comboBoxIdCity.Text,
                comboBoxIdSubscriber.Text,
                textBoxMinute.Value,
                comboBoxRDay.Text,
                comboBoxRDay.Text
                );

            if (conversationModel.validate(errorCity, errorSubscribe, errorMinute))
            {
                commandString = $@"
						INSERT INTO [dbo].[Conversation]
							   ([IdSubScriber]
							   ,[IdCity]
							   ,[Date]
							   ,[CountMinutes]
							   ,[TimesOfDay]
							   ,[PriceConverstation])
						 VALUES
							   (
								'{conversationModel.IDSubscriber}',
								'{conversationModel.IDCity}',
								'{conversationModel.date.ToShortDateString()}',
								'{conversationModel.CountMinutes}',
								'{conversationModel.date.ToShortTimeString()}',
								'{conversationModel.PriceConverstation}'
								)"                                ;

                sqlConnection = new SqlConnection(con);
                try
                {
                    sqlConnection.Open();
                }
                catch (Exception)
                {
                    MessageBox.Show("Не удалось подключиться");
                }
                command = new SqlCommand(commandString, sqlConnection);
                command.ExecuteNonQuery();
                sqlConnection.Close();

                DataTable DT = dataGridView1.DataSource as DataTable;
                DT.Clear();
                adapter.Fill(tableConversation);


                ValidateController.CleanerNumeric(textBoxMinute);
            }
            else
            {
                MessageBox.Show("Заполните данные");
            }
        }
Exemplo n.º 9
0
        public async void GivenAValidateRequest_WhenTheServerDoesNotSupportValidate_ThenANotSupportedErrorIsReturned()
        {
            ValidateController disabledValidateController = GetController(false);
            Resource           payload = new Observation();

            OperationNotImplementedException ex = await Assert.ThrowsAsync <OperationNotImplementedException>(() => disabledValidateController.Validate(payload, profile: null, mode: null));

            CheckOperationOutcomeIssue(
                ex,
                OperationOutcome.IssueSeverity.Error,
                OperationOutcome.IssueType.NotSupported,
                Resources.ValidationNotSupported);
        }
        public void Validate()
        {
            // Arrange
            LoginData loginData = TestSetup.TestLogin();

            ValidateController validateController = new ValidateController();

            // Act
            var actionResult = validateController.Get(loginData.sessionkey).Result;

            // Assert
            Assert.IsType <OkObjectResult>(actionResult);
        }
        public void TestGetIsValid(bool validatorResult, bool expectedResult, string expectedError)
        {
            var taxFileNumber = "1234";
            var validatorMock = new Mock <ITfnValidator>();

            validatorMock.Setup(p => p.Validate(taxFileNumber)).Returns(validatorResult);

            var controller = new ValidateController(validatorMock.Object);
            var result     = controller.GetIsValid(taxFileNumber);

            Assert.AreEqual(expectedResult, result.result);
            Assert.AreEqual(expectedError, result.error);
            validatorMock.VerifyAll();
        }
Exemplo n.º 12
0
        private void Button1_Click(object sender, EventArgs e)
        {
            subscribeModel = new SubscribeModel(textBoxNumber.Text, textBoxInn.Text, textBoxAddress.Text);
            if (subscribeModel.validate(errorNumber, errorINN, errorAddress))
            {
                Cursor.Current = Cursors.WaitCursor;
                sqlConnection  = new SqlConnection(con);
                if (ValidateController.validateItem(idSubscriber.Text))
                {
                    commandString = $@"UPDATE [dbo].[Subscribers]
								   SET [NumberPhone] = '{subscribeModel.MobilePhone}'
									  ,[INN] = '{subscribeModel.INN}'
									  ,[Address] = '{subscribeModel.Address}'
								 WHERE IdSubscriber = '{idSubscriber.Text}'"                                ;
                }
                else
                {
                    commandString = $@"INSERT INTO [dbo].[Subscribers]
						   ([NumberPhone]
						   ,[INN]
						   ,[Address])
					 VALUES(
						    '{subscribeModel.MobilePhone}',
							'{subscribeModel.INN}',
							'{subscribeModel.Address}')"                            ;
                }

                try
                {
                    sqlConnection.Open();
                }
                catch (Exception)
                {
                    MessageBox.Show("Не удалось подключиться");
                }


                command = new SqlCommand(commandString, sqlConnection);
                command.ExecuteNonQuery();
                this.subscribersTableAdapter2.Fill(this.phoneCallDataSet15.Subscribers);

                idSubscriber.Text = "";
                ValidateController.CleanerTextBox(textBoxAddress, textBoxInn, textBoxNumber);
                Cursor.Current = Cursors.Default;
            }
            else
            {
                MessageBox.Show("Заполните данные");
            }
        }
Exemplo n.º 13
0
        private void Button1_Click(object sender, EventArgs e)
        {
            cityModel = new CityModel(textBoxCity.Text, numericRateDay.Value, numericRateNight.Value, numericDiscount.Value);
            if (cityModel.validate(errorCity, errorRDay, errorRNight))
            {
                Cursor.Current = Cursors.WaitCursor;
                sqlConnection  = new SqlConnection(con);

                if (ValidateController.validateItem(labelIDCity.Text))
                {
                    commandString = $@"UPDATE [dbo].[City]
								   SET [NameCity] = '{cityModel.CityName}'
									  ,[RateDay] = '{cityModel.RateDay}'
									  ,[RateNigth] = '{cityModel.RateNight}'
									  ,[Discount] = '{cityModel.Discount}'
								   WHERE IdCity = '{labelIDCity.Text}'"                                ;
                }
                else
                {
                    commandString = $@"INSERT INTO [dbo].[City]
							   ([NameCity]
							   ,[RateDay]
							   ,[RateNigth]
							   ,[Discount])
					 VALUES(
						    '{cityModel.CityName}',
							'{cityModel.RateDay.ToString()}',
							'{cityModel.RateNight}',
							'{cityModel.Discount}')"                            ;
                }

                try
                {
                    sqlConnection.Open();
                }
                catch (Exception)
                {
                    MessageBox.Show("Не удалось подключиться");
                }
                command = new SqlCommand(commandString, sqlConnection);
                command.ExecuteNonQuery();
                this.cityTableAdapter.Fill(this.phoneCallDataSet19.City);


                labelIDCity.Text = "";
                ValidateController.CleanerTextBox(textBoxCity);
                ValidateController.CleanerNumeric(numericDiscount, numericRateDay, numericRateNight);
            }
        }
Exemplo n.º 14
0
 private double?CalculationPriceMinutes(string rDay, string rNight, decimal countMIn)
 {
     if (ValidateController.validateItem(rDay) && ValidateController.validateItem(rNight))
     {
         if (date.TimeOfDay.Hours > 12)
         {
             return(Convert.ToDouble(rDay) * Convert.ToDouble(countMIn));
         }
         else
         {
             return(Convert.ToDouble(rNight) * Convert.ToDouble(countMIn));
         }
     }
     return(null);
 }
Exemplo n.º 15
0
        public void TestValidateToken_ValidFalse()
        {
            try
            {
                ValidateController validate = new ValidateController();

                var validateFunc = new TestDelegate <string>(validate.Post);
                var validateTask = Task.Run(() => this.RunTestAsync(validateFunc));
                validateTask.Wait();

                var result    = validateTask.Result as ContentResult;
                var validated = JsonConvert.DeserializeObject <bool>((validateTask.Result as ContentResult).Content);

                Assert.False(validated);
            }
            catch (Exception e)
            {
                m_logger.WriteLine(e.Message);
                Assert.Null(e);
            }
        }
        private ValidateController NewValidateController(Mock <HttpContext> context, Mock <IInstance> instanceServiceMock, Mock <IData> dataServiceMock, Mock <IApplication> appServiceMock)
        {
            Mock <IRegister> registerServiceMock = new Mock <IRegister>();

            registerServiceMock
            .Setup(x => x.GetParty(It.IsAny <int>()))
            .Returns(Task.FromResult(new Party()
            {
                PartyId = partyId
            }));

            Mock <IProfile> profileServiceMock = new Mock <IProfile>();

            profileServiceMock
            .Setup(x => x.GetUserProfile(It.IsAny <int>()))
            .Returns(Task.FromResult(new UserProfile()
            {
                UserId = userId
            }));

            Mock <IOptions <GeneralSettings> > generalSettingsMock = new Mock <IOptions <GeneralSettings> >();

            generalSettingsMock.Setup(s => s.Value).Returns(new GeneralSettings()
            {
                AltinnPartyCookieName = "AltinnPartyId",
            });

            ServiceRepositorySettings serviceRepositorySettings = new ServiceRepositorySettings()
            {
                RepositoryLocation = repoPath,
            };

            Mock <ServiceContext> serviceContextMock   = new Mock <ServiceContext>();
            Mock <IExecution>     executionServiceMock = new Mock <IExecution>();

            executionServiceMock
            .Setup(e => e.GetServiceContext(org, app, It.IsAny <bool>()))
            .Returns(serviceContextMock.Object);

            ServiceImplementation serviceImplementation = new ServiceImplementation();

            executionServiceMock
            .Setup(e => e.GetServiceImplementation(org, app, It.IsAny <bool>()))
            .Returns(serviceImplementation);

            Mock <IPlatformServices> platformServicesMock = new Mock <IPlatformServices>();

            Mock <IObjectModelValidator> objectValidator = new Mock <IObjectModelValidator>();

            objectValidator.Setup(o => o.Validate(
                                      It.IsAny <ActionContext>(),
                                      It.IsAny <ValidationStateDictionary>(),
                                      It.IsAny <string>(),
                                      It.IsAny <object>()));

            ValidateController validateController = new ValidateController(
                generalSettingsMock.Object,
                registerServiceMock.Object,
                instanceServiceMock.Object,
                dataServiceMock.Object,
                executionServiceMock.Object,
                profileServiceMock.Object,
                platformServicesMock.Object,
                new Mock <IInstanceEvent>().Object,
                appServiceMock.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = context.Object,
                },

                ObjectValidator = objectValidator.Object,
            };

            return(validateController);
        }
Exemplo n.º 17
0
        public bool validate(Label labelMob, Label labelInn, Label labelAddress)
        {
            bool result = ValidateController.validateItem(MobilePhone, labelMob) && ValidateController.validateItem(INN, labelInn) && ValidateController.validateItem(Address, labelAddress);

            return(result);
        }
        public async Task ValidateInstance_Validation_ReturnsNoError()
        {
            // Arrange
            Application application = new Application
            {
                Id           = $"{org}/{app}",
                ElementTypes = new List <ElementType>
                {
                    new ElementType
                    {
                        Id                 = "default",
                        AppLogic           = true,
                        AllowedContentType = new List <string> {
                            "application/xml"
                        },
                        Task = "FormFilling_1"
                    }
                }
            };

            Instance getInstance = new Instance
            {
                Id = $"{instanceOwnerId}/{instanceGuid}",
                InstanceOwnerId = $"{instanceOwnerId}",
                AppId           = $"{org}/{app}",
                Org             = org,
                Process         = new ProcessState
                {
                    CurrentTask = new ProcessElementInfo {
                        AltinnTaskType = "FormFilling", ElementId = "FormFilling_1"
                    }
                },
                Data = new List <DataElement>
                {
                    new DataElement
                    {
                        Id          = $"{dataGuid}",
                        ElementType = "default",
                        StorageUrl  = "www.storageuri.com",
                        ContentType = "application/xml"
                    }
                }
            };

            Skjema model = new Skjema();

            FileStream         dataElement = File.OpenRead("Runtime/data/data-element.xml");
            Mock <HttpRequest> request     = MockRequest();

            request.SetupGet(x => x.Body).Returns(dataElement);

            var context = new Mock <HttpContext>();

            context.SetupGet(x => x.Request).Returns(request.Object);
            context.SetupGet(x => x.User).Returns(MockUser().Object);

            Mock <IApplication> appServiceMock = new Mock <IApplication>();

            appServiceMock
            .Setup(i => i.GetApplication(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult(application));

            Mock <IInstance> instanceServiceMock = new Mock <IInstance>();

            instanceServiceMock
            .Setup(i => i.GetInstance(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.Is <Guid>(g => g.Equals(instanceGuid))))
            .Returns(Task.FromResult(getInstance));

            Mock <IData> dataServiceMock = new Mock <IData>();

            dataServiceMock
            .Setup(d => d.GetFormData(It.IsAny <Guid>(), It.IsAny <Type>(), org, app, instanceOwnerId, It.IsAny <Guid>()))
            .Returns(model);

            ValidateController target = NewValidateController(context, instanceServiceMock, dataServiceMock, appServiceMock);

            // Act
            IActionResult result = await target.ValidateInstance(org, app, instanceOwnerId, instanceGuid);

            OkObjectResult actual = result as OkObjectResult;

            // Arrange
            Assert.NotNull(actual);

            List <ValidationIssue> validationIssues = actual.Value as List <ValidationIssue>;

            Assert.NotNull(validationIssues);
            Assert.Empty(validationIssues);
        }