public Point GetCoordinates()
        {
            int x = RandomGen.Next(TopLeft.X, BottomRight.X);
            int y = RandomGen.Next(TopLeft.Y, BottomRight.Y);

            return(new Point(x, y));
        }
Exemple #2
0
        public async Task ShouldAddCredits()
        {
            var testServer = await GetTestServer();

            var client = testServer.CreateClient();
            var model  = await CreateUserAsync(client);

            var additionAmount = RandomGen.Next(1000);
            var response       = await client.GetAsync($"api/v1/users/{model.Email}");

            var user = await response.ReadAsync <Domain.Model.UserModel.User>();

            var command = new AddSmsCreditsCommand(Guid.NewGuid(), (int)user.Id, additionAmount, true);

            response = await client.PostAsync($"{ApiPath}", command.ToJsonContent());

            response.EnsureSuccessStatusCode();
            response = await client.GetAsync($"api/v1/users/{model.Email}");

            user = await response.ReadAsync <Domain.Model.UserModel.User>();

            user.SmsBalance.Should().Be(additionAmount);
            Consumer.Instance.GetAll <ISmsCreditAdded>()
            .Should().Contain(x =>
                              x.Amount == command.Amount &&
                              x.Email == user.Email &&
                              x.Phone == user.Phone);
        }
Exemple #3
0
        public void IncorrectKeyForDecryption()
        {
            var keyGenerator = new AesManaged();

            keyGenerator.GenerateKey();
            var key1 = Convert.ToBase64String(keyGenerator.Key);

            keyGenerator.GenerateKey();
            var key2 = Convert.ToBase64String(keyGenerator.Key);

            Assert.AreNotEqual(key1, key2);

            var plain = _randomWords.Sentence(RandomGen.Next(20, 99));

            var crypto1 = new AesCryptString(key1);
            var cipher  = crypto1.Encrypt(plain);

            var plain2 = crypto1.Decrypt(cipher); // this should work.

            Assert.AreEqual(plain, plain2);
            try
            {
                crypto1.Decrypt(key2, cipher); // this should fail
                Assert.Fail("Expected this decrypt to fail because the key was not provided.");
            }
            catch (CryptographicException error)
            {
                Assert.IsTrue(Regex.IsMatch(error.Message, "can not decrypt this text", RegexOptions.IgnoreCase),
                              error.Message);
            }
        }
        public async Task DeleteStudentForms()
        {
            var examId    = RandomGen.Next();
            var userId    = RandomGen.Next();
            var studentId = RandomGen.Next();

            using (var testServer = Create(userId))
            {
                var forms    = GenerateStudentForms(examId, userId, studentId);
                var client   = testServer.CreateClient();
                var response = await client.PostAsync(ApiPath, forms.ToJsonContent());

                response.EnsureSuccessStatusCode();
                var studentOpticalForms = await GetListAsync <StudentOpticalForm>(client, examId);

                studentOpticalForms.Should()
                .HaveCount(1)
                .And
                .Contain(s => s.StudentId == studentId);
                var repository = testServer.Host.Services.GetService(typeof(IOpticalFormRepository));
                var consumer   = new StudentDeletedConsumer(repository as IOpticalFormRepository, null);
                var context    = Substitute.For <ConsumeContext <IStudentDeleted> >();
                context.Message.StudentId.Returns(studentId);
                await consumer.Consume(context);

                studentOpticalForms = await GetListAsync <StudentOpticalForm>(client, examId);

                studentOpticalForms.Should().BeEmpty();
            }
        }
Exemple #5
0
        IEnumerator behaviorGen()
        {
            var movable = GetComponent <CharMoveComponent>();

            while (true)
            {
                int walk_time = RandomGen.Next(100, 150);
                movable.move_direction = Direction.Right;
                for (int i = 0; i < walk_time; i++)
                {
                    yield return(null);
                }

                movable.move_direction = Direction.None;
                for (int i = 0; i < RandomGen.Next(700, 2000); i++)
                {
                    yield return(null);
                }

                movable.move_direction = Direction.Left;
                for (int i = 0; i < walk_time; i++)
                {
                    yield return(null);
                }

                movable.move_direction = Direction.None;
                for (int i = 0; i < RandomGen.Next(700, 2000); i++)
                {
                    yield return(null);
                }
            }
        }
Exemple #6
0
        public void ForgotToInitializeKeyForDecryption()
        {
            var crypto1 = new AesCryptString();

            var plain = _randomWords.Sentence(RandomGen.Next(20, 99));

            var crypt = crypto1.Encrypt(plain);

            var plain2 = crypto1.Decrypt(crypt);

            Assert.AreEqual(plain, plain2);

            // Verify that unset decryption key provides a useful message
            var crypto2 = new AesCryptString();

            try
            {
                crypto2.Decrypt(crypt);
                Assert.Fail("Expected this decrypt to fail because we haven't set the key yet.");
            }
            catch (CryptographicException error)
            {
                Assert.IsTrue(Regex.IsMatch(error.Message, "decryption key not set", RegexOptions.IgnoreCase),
                              error.Message);
            }
        }
        public async Task ShouldDeleteTheForm_And_ReevaluateTheExam()
        {
            var userId = RandomGen.Next(10000);

            using (var testServer = Create(userId))
            {
                var client = testServer.CreateClient();

                var forms = new List <StudentOpticalForm>
                {
                    new StudentOpticalForm('A')
                    {
                        ExamId    = RandomGen.Next(),
                        StudentId = RandomGen.Next(),
                        UserId    = userId.ToString(),
                        Sections  = new List <StudentOpticalFormSection>
                        {
                            new StudentOpticalFormSection(1, "TEST"),
                        },
                    },
                };
                var response = await client.PostAsync(ApiPath, forms.ToJsonContent());

                response.EnsureSuccessStatusCode();
                var form = (await GetListAsync <StudentOpticalForm>(
                                client, forms.First().ExamId)).First();
                await client.DeleteAsync($"{ApiPath}/{form.Id}");

                form = (await GetListAsync <StudentOpticalForm>(
                            client, forms.First().ExamId)).FirstOrDefault();
                form.Should().BeNull();
                var events = Consumer.Instance.GetAll <IEvaluateExam>().ToList();
                events.Should().Contain(e => e.ExamId == forms.First().ExamId);
            }
        }
Exemple #8
0
        public async Task ShouldAddStudentOpticalForms()
        {
            var userId = RandomGen.Next(10000);

            using (var testServer = Create(userId))
            {
                var examId = RandomGen.Next();
                var client = testServer.CreateClient();
                var forms  = new List <StudentOpticalForm>
                {
                    GenerateStudentForm(examId, userId),
                    GenerateStudentForm(examId, userId),
                    GenerateStudentForm(examId, userId),
                    GenerateStudentForm(examId, userId),
                    GenerateStudentForm(examId, userId),
                    GenerateStudentForm(examId, userId),
                };
                var response = await client.PostAsync(ApiPath, forms.ToJsonContent());

                response.EnsureSuccessStatusCode();
                var examForms = await GetListAsync <StudentOpticalForm>(client, examId);

                examForms.Select(e => e.StudentNumber)
                .Should().BeEquivalentTo(forms.Select(e => e.StudentNumber));
                examForms.Select(e => e.ExamId)
                .Should().BeEquivalentTo(forms.Select(e => e.ExamId));
                examForms.Select(e => e.Booklet)
                .Should().BeEquivalentTo(forms.Select(e => e.Booklet));
            }
        }
Exemple #9
0
        private SpleefDecision ChooseRandomSurvivalDirection(SpleefBoard.SpleefBoard board, Point myLocation)
        {
            var possibilities = new List <SpleefDecision>();

            possibilities.Add(SpleefDecision.DefaultDecision);

            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    if (j != 0 || i != 0)
                    {
                        var moveAction = new SpleefDecision(SpleefAction.Move, new Point(i, j));

                        if (moveAction.IsValid)
                        {
                            var dest = new Point(myLocation.X + moveAction.Target.X, myLocation.Y + moveAction.Target.Y);

                            if (dest.X >= 0 && dest.X < board.Width && dest.Y >= 0 && dest.Y < board.Height)
                            {
                                if (board[dest.X, dest.Y].IsSolid)
                                {
                                    possibilities.Add(moveAction);
                                }
                            }
                        }
                    }
                }
            }

            return(possibilities[RandomGen.Next(0, possibilities.Count)]);
        }
Exemple #10
0
        public async Task GiveStudentEndpoint_Should_ReturnAllOpticalFormsOfStudent()
        {
            var userId    = RandomGen.Next();
            var studentId = RandomGen.Next();

            using (var testServer = Create(userId))
            {
                var forms = new List <StudentOpticalForm>
                {
                    GenerateStudentForm(RandomGen.Next(), userId),
                    GenerateStudentForm(RandomGen.Next(), userId),
                    GenerateStudentForm(RandomGen.Next(), userId),
                    GenerateStudentForm(RandomGen.Next(), userId),
                };
                foreach (var form in forms)
                {
                    form.StudentId = studentId;
                }

                var client = testServer.CreateClient();
                await client.PostAsync(ApiPath, forms.ToJsonContent());

                var returnedForms = await GetStudentFormsByStudentIdAsync(client, studentId);

                returnedForms.Should().HaveCount(forms.Count);
            }
        }
        public async Task UpdateLessonNamesOfOpticalForms()
        {
            var lessonId       = RandomGen.Next();
            var lessonName     = RandomGen.String(20);
            var answerKeyForms = GenerateAnswerKeyOpticalForms(3, lessonId, lessonName).ToList();
            var userId         = RandomGen.Next(10000);

            using (var testServer = Create(userId))
            {
                var client = testServer.CreateClient();
                var examId = await ExecuteExamCreatedConsumerAsync(testServer, answerKeyForms);

                var forms = new List <StudentOpticalForm>
                {
                    GenerateStudentForm(examId, userId, lessonId, lessonName),
                    GenerateStudentForm(examId, userId, lessonId, lessonName),
                    GenerateStudentForm(examId, userId, lessonId, lessonName),
                    GenerateStudentForm(examId, userId, lessonId, lessonName),
                    GenerateStudentForm(examId, userId, lessonId, lessonName),
                    GenerateStudentForm(examId, userId, lessonId, lessonName),
                };
                var response = await client.PostAsync(ApiPath, forms.ToJsonContent());

                response.EnsureSuccessStatusCode();
                var studentOpticalForms = await GetListAsync <StudentOpticalForm>(client, examId);

                studentOpticalForms.SelectMany(f => f.Sections)
                .Should().NotContain(s => s.LessonName != lessonName);

                var newLessonName = RandomGen.String(20);
                var repository    = testServer.Host.Services.GetService(typeof(IOpticalFormRepository));
                var consumer      = new LessonNameChangedConsumer(repository as IOpticalFormRepository);
                var context       = Substitute.For <ConsumeContext <ILessonNameChanged> >();
                context.Message.LessonId.Returns(lessonId);
                context.Message.NewLessonName.Returns(newLessonName);
                await consumer.Consume(context);

                studentOpticalForms = await GetListAsync <StudentOpticalForm>(client, examId);

                studentOpticalForms.SelectMany(f => f.Sections)
                .Select(s => s.LessonName)
                .Distinct()
                .ToList()
                .Should()
                .HaveCount(1)
                .And
                .Contain(newLessonName);
                var answerKeyOpticalForms = await GetListAsync <AnswerKeyOpticalForm>(client, examId);

                answerKeyOpticalForms.SelectMany(f => f.Sections)
                .Select(s => s.LessonName)
                .Distinct()
                .ToList()
                .Should()
                .HaveCount(1)
                .And
                .Contain(newLessonName);
            }
        }
Exemple #12
0
        private static void OnWriterEvent(object sender, NETUtils.ModuleWriterListener.ModuleWriterListenerEventArgs e)
        {
            var writer = (ModuleWriterBase)sender;

            if (e.WriterEvent == ModuleWriterEvent.MDEndCreateTables)
            {
                int r = random.Next(8, 16);
                for (int i = 0; i < r; i++)
                {
                    writer.MetaData.TablesHeap.ENCLogTable.Add(new RawENCLogRow((uint)random.Next(), (uint)random.Next()));
                }
                r = random.Next(8, 16);
                for (int i = 0; i < r; i++)
                {
                    writer.MetaData.TablesHeap.ENCMapTable.Add(new RawENCMapRow((uint)random.Next()));
                }
            }
        }
Exemple #13
0
 public void Shuffle(int from = 0)
 {
     for (int i = from; i < 52 - 1; i++)
     {
         int   n    = RandomGen.Next(from, 52);
         ulong temp = cards[i]; // could skip if n == i
         cards[i] = cards[n];
         cards[n] = temp;
     }
 }
 private QuestionAnswer GenerateAnswer()
 {
     return(new QuestionAnswer()
     {
         Answer = Answers.Random(),
         QuestionNo = RandomGen.Next(100),
         SubjectName = RandomGen.String(250),
         SubjectId = RandomGen.Next(),
     });
 }
    public static float Give1to2()
    {
        // var ret = 1 + Mathf.Clamp((RandomGen.Next() * (1 / int.MaxValue)), 0, 1);

        var ret = (float)(1 + (RandomGen.Next(10, 0) * 0.1f));

        // Debug.Log(ret);

        return(ret);
    }
Exemple #16
0
        public void CryptRandomPolyVigenere()
        {
            var password = RandomGen.RName(RandomGen.Next(2, 5), Crypt.Map[0]);
            var test = new Crypt(0, password);

            var crypt = test.ToCrypt(plainText0);
            var plain = test.ToPlain(crypt);

            Assert.AreEqual(plainText0, plain);
        }
Exemple #17
0
        private static string GenerateString()
        {
            string s = "";

            for (int i = 0; i < 3; i++)
            {
                s += (char)random.Next(8000, 8500);
            }
            return(s);
        }
Exemple #18
0
        public void CryptVigenereInstantiate()
        {
            var password = RandomGen.RName(RandomGen.Next(2, 5), Crypt.Map[0]);
            var test = new Crypt(0, password);

            Assert.IsNotNull(test);

            Assert.AreEqual(password.Length, test.Poly.Length);

            Console.WriteLine(test.ToString());
        }
Exemple #19
0
        public void CryptRandomPolyInstantiate()
        {
            var numPoly = RandomGen.Next(1, 8);

            var test = new Crypt(0, "foGarbee", numPoly);
            Assert.IsNotNull(test);

            Assert.AreEqual(numPoly, test.Poly.Length);

            Console.WriteLine(test.ToString());
        }
Exemple #20
0
        public void CryptRandomPolyCipher()
        {
            var numPoly = RandomGen.Next(1, 8);

            var test = new Crypt(0, "foGarbee", numPoly);

            var crypt = test.ToCrypt(plainText0);
            var plain = test.ToPlain(crypt);

            Assert.AreEqual(plainText0, plain);
        }
Exemple #21
0
 public override DilemmaDecision PlayTurn(DilemmaPlayerInfo currentOpponent, Dictionary <PlayerInfo, int> allPlayersAndScores, List <DilemmaGame> completeHistory)
 {
     if (RandomGen.Next(100) < 50)
     {
         return(new DilemmaDecision(DilemmaAction.Cover));
     }
     else
     {
         return(new DilemmaDecision(DilemmaAction.Betray));
     }
 }
Exemple #22
0
        public async Task FormWithScoreShouldBeAdded()
        {
            var scoreFormula = new ScoreFormula(100, "5. Grade");

            scoreFormula.Coefficients.Add(new LessonCoefficient("Turkish", 3.333f));
            scoreFormula.Coefficients.Add(new LessonCoefficient("Social Science", 3.333f));
            scoreFormula.Coefficients.Add(new LessonCoefficient("Basic Mathematics", 3.334f));
            scoreFormula.Coefficients.Add(new LessonCoefficient("Science", 3.334f));
            var answerKeyForm = new AnswerKeyOpticalForm(
                'A',
                new List <ScoreFormula> {
                scoreFormula
            });

            answerKeyForm.AddSection(new AnswerKeyOpticalFormSection(1, "Turkish", 40, 1, 1)
            {
                Answers = ParseAnswers("CECBEEBADEEBACBDBBEDDAEDDACEABDEDCBDBABD"),
            });
            answerKeyForm.AddSection(new AnswerKeyOpticalFormSection(6, "Social Science", 20, 1, 2)
            {
                Answers = ParseAnswers("EAEADADECEEDCDEAEDBA"),
            });
            answerKeyForm.AddSection(new AnswerKeyOpticalFormSection(5, "Basic Mathematics", 40, 2, 3)
            {
                Answers = ParseAnswers("DDBECACAACBCBECAEAADCDCDEDABAACCBDBAEDCB"),
            });
            answerKeyForm.AddSection(new AnswerKeyOpticalFormSection(2, "Science", 20, 2, 4)
            {
                Answers = ParseAnswers("DBCCEEBAEECAACBBDECE"),
            });
            var studentForm = new StudentOpticalForm('A');

            studentForm.SetFromScanOutput(new ScanOutput("CE EEE       C   EA DAE  ADEBEDEDCADEBAEDBE     D  B DEAEAAA", 1), answerKeyForm);
            studentForm.SetFromScanOutput(new ScanOutput("CB                                      A     CE  D         ", 2), answerKeyForm);
            studentForm.Evaluate(4, answerKeyForm.ScoreFormulas);

            var userId = RandomGen.Next(10000);

            studentForm.UserId = userId.ToString();
            studentForm.ExamId = RandomGen.Next();

            using (var testServer = Create(userId))
            {
                var client = testServer.CreateClient();

                var forms = new List <StudentOpticalForm>
                {
                    studentForm,
                };
                var response = await client.PostAsync(ApiPath, forms.ToJsonContent());

                response.EnsureSuccessStatusCode();
            }
        }
Exemple #23
0
        public Town(TownOptions options)
        {
            Options = options;
            //  Random = new Random (options.Seed);

            SplinesToRender = new List <Dictionary <Den.Tools.Coord, List <UnityEngine.Vector3> > >();

            Random = new Random(options.Seed + RandomGen.Next());

            mapOffset  = options.mapOffset;
            townOffset = options.townOffset;

            var ok = false;

            while (!ok)
            {
                NumPatches = options.Patches;

                name = TownGlobalObjectService.NamesQueue.Dequeue();

                //var addendum =
                //    ((Options.coord.z > 0) ? "N" : "S")
                //    +
                //    ((Options.coord.x > 0) ? "E" : "W");

                //name += "_" + addendum;

                //name = TownGlobalObjectService.namegenref.GeneratePlace();
                //  name = "cityWith"+ NumPatches+"Patches"; // TownGlobalObjectService.namegenref.GeneratePlace();

                Roads       = new List <List <Vector2> > ();
                Streets     = new List <List <Vector2> > ();
                Gates       = new List <Vector2> ();
                Center      = new Vector2(Width / 2f * (1f + 0.1f * Random.value - 0.1f * Random.value), Height / 2f * (1f + 0.1f * Random.value - 0.1f * Random.value));
                Patches     = new List <Patch> ();
                WaterBorder = new List <Vector2> ();

                try
                {
                    BuildPatches();
                    OptimizePatches();
                    BuildWalls();
                    BuildRoads();
                    PopulateTown();

                    ok = Roads.Count > 1;
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
            }
        }
        public List <Common.Passenger> GenerateGroundPassengers(string flightId)
        {
            List <Common.Passenger> result = new List <Common.Passenger>();
            int count = RandomGen.Next(Common.Passenger.MinGeneratedPassengerCount,
                                       Common.Passenger.MaxGeneratedPassengerCount + 1);

            for (int i = 0; i < count; i++)
            {
                result.Add(new Common.Passenger(flightId, false));
            }
            return(result);
        }
Exemple #25
0
        public void CryptSansKey()
        {
            var crypto = new AesCryptString("Q+pJALEKLqzBYWrctPUz64DXZK9zEQW5NuWOtSdPeCM=");

            var plain = _randomWords.Sentence(RandomGen.Next(20, 99));

            var crypt = crypto.Encrypt(plain);

            var plain2 = crypto.Decrypt(crypt);

            Assert.AreEqual(plain, plain2);
        }
Exemple #26
0
        protected async Task <int> ExecuteExamCreatedConsumerAsync(TestServer testServer, List <AnswerKeyOpticalForm> answerKeyOpticalForms)
        {
            var examId     = RandomGen.Next();
            var repository = testServer.Host.Services.GetService(typeof(IOpticalFormRepository));
            var consumer   = new ExamCreatedConsumer(repository as IOpticalFormRepository);
            var context    = Substitute.For <ConsumeContext <IExamCreated> >();

            context.Message.ExamId.Returns(examId);
            context.Message.AnswerKeyOpticalForms.Returns(answerKeyOpticalForms);
            await consumer.Consume(context);

            return(examId);
        }
Exemple #27
0
 static PlaneHandler()
 {
     Planes = new List <Common.Plane>(4);
     for (int i = 0; i < 4; i++)
     {
         int passengerCount = RandomGen.Next(1, Common.Plane.PassengerCapacity + 1);
         Planes.Add(GeneratePlane(passengerCount));
     }
     h1free             = true;
     h2free             = true;
     PlaneHandlerThread = new Thread(HandlePlanes);
     PlaneHandlerThread.Start();
 }
Exemple #28
0
        private static void RemovePlane(Common.Plane plane)
        {
            string URL = String.Format("{0}/Despawn?id={1}",
                                       ServiceStrings.Vis, plane.Id);

            CommonUtil.MakeRequest(URL);
            Planes.Remove(plane);
            if (Planes.Count < 4)
            {
                int passengerCount = RandomGen.Next(1, Common.Plane.PassengerCapacity + 1);
                plane = GeneratePlane(passengerCount);
                Planes.Add(plane);
            }
        }
 private AnswerKeyQuestionAnswer GenerateAnswerKeyQuestionAnswer()
 {
     return(new AnswerKeyQuestionAnswer()
     {
         Answer = "ABCDE".Random(),
         QuestionNo = RandomGen.Next(100),
         SubjectName = RandomGen.String(250),
         SubjectId = RandomGen.Next(),
         QuestionNoBookletB = RandomGen.Next(100),
         QuestionNoBookletC = RandomGen.Next(100),
         QuestionNoBookletD = RandomGen.Next(100),
         QuestionAnswerCancelAction = QuestionAnswerCancelAction.None,
     });
 }
Exemple #30
0
        public async Task ShouldUpdateUser()
        {
            using (var testServer = await CreateAsync())
            {
                var client            = testServer.CreateClient();
                var createUserCommand = await CreateUserAsync(client, testServer.Host.Services);

                var response = await client.GetAsync(ApiPath);

                var users = await response.ReadAsync <IReadOnlyCollection <UserReadModel> >();

                var user = users.First(u => u.Email == createUserCommand.Email);
                var city = await GetRandomCityAsync(client);

                var command = new UpdateUserByAdminCommand(
                    Guid.NewGuid(),
                    user.Id,
                    RandomGen.String(5),
                    RandomGen.String(5),
                    user.SubjectId,
                    RandomGen.String(100),
                    "5544205163",
                    city.Id,
                    city.Districts.Random().Id,
                    $"{RandomGen.String(120)}@hotmail.com",
                    RandomGen.Next(10),
                    RandomGen.Next(300) + 100,
                    true,
                    RandomGen.Next(4) + 1,
                    DateTime.Now.AddDays(200));
                response = await client.PostAsync(
                    $"{ApiPath}/update-by-admin",
                    command.ToJsonContent());

                response.EnsureSuccessStatusCode();
                response = await client.GetAsync(ApiPath);

                users = await response.ReadAsync <IReadOnlyCollection <UserReadModel> >();

                users.First(u => u.Id == user.Id)
                .Should().Match <UserReadModel>(
                    u => u.Email == command.Email &&
                    u.SchoolName == command.SchoolName &&
                    u.FirstName == command.FirstName &&
                    u.LastName == command.LastName &&
                    u.CityId == command.CityId &&
                    u.DistrictId == command.DistrictId &&
                    u.Phone == command.MobilePhone);
            }
        }