Exemple #1
0
        public async Task NewQuestionCanBeCreated()
        {
            var command = new CreateQuestionDTO()
            {
                CatalogId = TestUtils.ValidQuestionsCatalog1Id,
                Content   = "Who is your dady?",
                Answers   = new List <CreateAnswerDTO>()
                {
                    new CreateAnswerDTO()
                    {
                        Content = "Adam", IsCorrect = true
                    },
                    new CreateAnswerDTO()
                    {
                        Content = "Peter", IsCorrect = false
                    }
                }
            };

            var response = await client.PostAsync(EndpointName, command);

            AssertExt.EnsureSuccessStatusCode(response);

            var createdId      = response.GetContent <long>().Value;
            var context        = factory.GetService <TestCreationDbContext>();
            var actualQuestion = context.Questions.Include(x => x.Answers).FirstOrDefault(x => x.QuestionId == createdId);

            AssertExt.AreEquivalent(command, actualQuestion);
        }
Exemple #2
0
        public async Task TestCanBeRead(long testId)
        {
            var response = await client.GetAsync($"{EndpointName}/{testId}");

            AssertExt.EnsureSuccessStatusCode(response);

            var actualTest   = response.GetContent <TestDTO>().Value;
            var context      = factory.GetService <TestCreationDbContext>();
            var expectedTest = context.Tests.Include(x => x.Questions).ThenInclude(x => x.Question).FirstOrDefault(x => x.TestId == testId);

            AssertExt.AreEquivalent(expectedTest, actualTest);
        }
Exemple #3
0
        public async Task TestsCanBeReadForGivenOwner()
        {
            var response = await client.GetAsync($"{EndpointName}/?ownerId={TestUtils.OwnerId}");

            AssertExt.EnsureSuccessStatusCode(response);

            var actualTests   = response.GetContent <OffsetPagedResults <TestOnListDTO> >().Value;
            var context       = factory.GetService <TestCreationDbContext>();
            var expectedTests = context.Tests.Where(x => x.OwnerId == TestUtils.OwnerId).ToList();

            AssertExt.AreEquivalent(expectedTests, actualTests.Result);
        }
Exemple #4
0
        public async Task TestItemsCanBeReadForGivenTest(long testId)
        {
            var response = await client.GetAsync($"{EndpointName}/{testId}/questions/");

            AssertExt.EnsureSuccessStatusCode(response);

            var actualTestItems = response.GetContent <List <TestItemDTO> >().Value;
            var context         = factory.GetService <TestCreationDbContext>();
            var expectedTest    = context.Tests.Where(x => x.TestId == testId).Include(x => x.Questions).FirstOrDefault();

            AssertExt.AreEquivalent(expectedTest.Questions, actualTestItems);
        }
Exemple #5
0
        public async Task QuestionCanBeRead(long questionId)
        {
            var response = await client.GetAsync($"{EndpointName}/{questionId}/");

            AssertExt.EnsureSuccessStatusCode(response);

            var actualQuestion   = response.GetContent <QuestionWithAnswersDTO>().Value;
            var context          = factory.GetService <TestCreationDbContext>();
            var expectedQuestion = context.Questions.Include(x => x.Answers).FirstOrDefault(x => x.QuestionId == questionId);

            AssertExt.AreEquivalent(expectedQuestion, actualQuestion);
        }
Exemple #6
0
        public async Task QuestionsFromGivenCatalogCanBeRead(long catalogId)
        {
            var response = await client.GetAsync($"{EndpointName}/?catalogId={catalogId}");

            AssertExt.EnsureSuccessStatusCode(response);

            var actualQuestions   = response.GetContent <OffsetPagedResults <QuestionOnListDTO> >().Value;
            var context           = factory.GetService <TestCreationDbContext>();
            var expectedQuestions = context.Questions.Where(x => x.CatalogId == catalogId).ToList();

            AssertExt.AreEquivalent(expectedQuestions, actualQuestions.Result);
        }
Exemple #7
0
        public async Task CatalogCanBeRead(long catalogId)
        {
            var response = await client.GetAsync($"{EndpointName}/{catalogId}");

            AssertExt.EnsureSuccessStatusCode(response);

            var catalog         = response.GetContent <CatalogDTO>().Value;
            var context         = factory.GetService <TestCreationDbContext>();
            var expectedCatalog = context.QuestionsCatalogs.FirstOrDefault(x => x.CatalogId == catalogId);

            AssertExt.AreEquivalent(expectedCatalog, catalog);
        }
Exemple #8
0
        public async Task UsersCanBeReadByAdmin()
        {
            client = factory.CreateClient(ValidAdminToken);
            var response = await client.GetAsync(EndpointName);

            AssertExt.EnsureSuccessStatusCode(response);

            var userManagementContext = factory.GetService <UserManagementDbContext>();
            var expectedUsers         = userManagementContext.Users.ToList();

            var users = response.GetContent <CursorPagedResults <UserDTO> >().Value;

            AssertExt.AreEquivalent(expectedUsers, users.Result);
        }
Exemple #9
0
        public async Task QuestionsCanBeReadWithUsingPagination(int limit, int offset)
        {
            var response = await client.GetAsync($"{EndpointName}/?catalogId={TestUtils.ValidQuestionsCatalog2Id}&limit={limit}&offset={offset}");

            AssertExt.EnsureSuccessStatusCode(response);

            var actualQuestions   = response.GetContent <OffsetPagedResults <QuestionOnListDTO> >().Value;
            var context           = factory.GetService <TestCreationDbContext>();
            var expectedQuestions = context.Questions.Where(x => x.CatalogId == TestUtils.ValidQuestionsCatalog2Id && x.IsDeleted == false)
                                    .Skip(offset)
                                    .Take(limit)
                                    .ToList();

            AssertExt.AreEquivalent(expectedQuestions, actualQuestions.Result);
        }
Exemple #10
0
        public async Task ExistingTestCanBeUpdated(long testId, string title)
        {
            var command = new UpdateTestDTO
            {
                Title = title
            };

            var response = await client.PutAsync($"{EndpointName}/{testId}/", command);

            AssertExt.EnsureSuccessStatusCode(response);

            var context    = factory.GetService <TestCreationDbContext>();
            var actualTest = context.Tests.Find(testId);

            AssertExt.AreEquivalent(command, actualTest);
        }
Exemple #11
0
        public async Task NewTestCanBeCreated(long catalogId, string testTitle)
        {
            var command = new CreateTestDTO()
            {
                OwnerId = TestUtils.OwnerId, Title = testTitle
            };

            var response = await client.PostAsync(EndpointName, command);

            AssertExt.EnsureSuccessStatusCode(response);

            var createdTestId = response.GetContent <long>().Value;
            var context       = factory.GetService <TestCreationDbContext>();
            var actualTest    = context.Tests.Find(createdTestId);

            AssertExt.AreEquivalent(command, actualTest);
        }
Exemple #12
0
        public async Task TestItemCanBeAddedToTest(long testId, long questionId)
        {
            var command = new CreateTestItemDTO()
            {
                QuestionId = questionId
            };

            var response = await client.PostAsync($"{EndpointName}/{testId}/questions/", command);

            AssertExt.EnsureSuccessStatusCode(response);

            var addedItemId  = response.GetContent <long>().Value;
            var context      = factory.GetService <TestCreationDbContext>();
            var test         = context.Tests.Include(x => x.Questions).ThenInclude(x => x.Question).First(x => x.TestId == testId);
            var questionItem = test.Questions.FirstOrDefault(x => x.QuestionItemId == addedItemId);

            AssertExt.AreEquivalent(command, questionItem);
        }
Exemple #13
0
        private void TestParsingAndReporting(string testCaseName, WarehouseStateParserType parserType)
        {
            IWarehouseStateParser parser = WarehouseStateParserFactory.Create(parserType);
            string input          = LoadResource(testCaseName + ".in");
            string expectedOutput = LoadResource(testCaseName + ".out");

            string[] inputLines = input.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

            foreach (var line in inputLines)
            {
                parser.ParseLine(line);
            }

            var parsingResult = parser.GetResult();

            var    raportGenerator = new TextRaportGenerator();
            string output          = raportGenerator.Generate(parsingResult);

            AssertExt.AreEquivalent(expectedOutput, output);
        }
Exemple #14
0
        public async Task ExisitngQuestionCanBeUpdated(long questionId, long answerId)
        {
            var command = new UpdateQuestionDTO
            {
                Content = "Who is your momy?",
                Answers = new List <UpdateAnswerDTO>
                {
                    new UpdateAnswerDTO {
                        AnswerId = answerId, Content = "Alicia", IsCorrect = false
                    }
                },
                CatalogId        = TestUtils.ValidQuestionsCatalog2Id,
                ConcurrencyToken = 0
            };

            var response = await client.PutAsync($"{EndpointName}/{questionId}/", command);

            AssertExt.EnsureSuccessStatusCode(response);

            var context        = factory.GetService <TestCreationDbContext>();
            var actualQuestion = context.Questions.Include(x => x.Answers).FirstOrDefault(x => x.QuestionId == questionId);

            AssertExt.AreEquivalent(command, actualQuestion);
        }