public override void When()
 {
     var quizDate = TestValues.CARD_QUIZ_DATE;
     this.quizResult = new QuizResult { IsCorrect = false };
     this.card = new Card { Level = CARD_LEVEL, QuizDate = quizDate };
     this.QuizResultHandler.ApplyQuizResult(this.quizResult, this.card, quizDate.Year, quizDate.Month, quizDate.Day);
 }
Example #2
0
 public override void When()
 {
     this.expectedResult = new Card { PartitionKey = TestValues.PARTITION_KEY, RowKey = TestValues.ROW_KEY };
     var cards = new HashSet<Card> { new Card { PartitionKey = TestValues.PARTITION_KEY }, this.expectedResult, new Card() }.AsQueryable();
     this.TableStorageContext.Setup(x => x.CreateQuery<Card>()).Returns(cards);
     this.actualResult = this.TableStorageRepository.Get(TestValues.PARTITION_KEY, TestValues.ROW_KEY);
 }
 public override void When()
 {
     var quizDate = TestValues.CARD_QUIZ_DATE;
     this.quizResult = new QuizResult { IsCorrect = true };
     this.cardLevel = this.UserConfiguration.QuizCalendar.Count;
     this.card = new Card { Level = this.cardLevel, QuizDate = quizDate };
     this.QuizResultHandler.ApplyQuizResult(this.quizResult, this.card, quizDate.Year, quizDate.Month, quizDate.Day);
 }
Example #4
0
 public void ReverseQuizResult(QuizResult quizResult, Card card)
 {
     card.Level = quizResult.CardLevel;
     card.QuizDate = quizResult.CardQuizDate;
     card.IsCorrect = quizResult.CardIsCorrect;
     card.CompletedQuizYear = quizResult.CardCompletedQuizYear;
     card.CompletedQuizMonth = quizResult.CardCompletedQuizMonth;
     card.CompletedQuizDay = quizResult.CardCompletedQuizDay;
 }
Example #5
0
        public QuizViewModel()
        {
            var card = new Card { Question = "This value was set on the card" };

            this.Title = card.Question;
            this.CardCount = 10;
            this.CardsCompleted = 5;
            this.CardsCorrect = 3;
            this.CardsIncorrect = 2;
            this.QuizDate = DateTime.Now.ToString(DateTimeFormatInfo.CurrentInfo.ShortDatePattern);
            this.accessControlService = this.GetService<IAccessControlService>();

            //            var result = accessControlService.GetIdentityProviders().Result;
            //            this.Title = result.Select(x => x.Name).First();

            //            var httpClient = new HttpClient();
            //            var response = httpClient.GetAsync(Urls.IDENTITY_PROVIDERS).Result;
            //            var json = response.Content.ReadAsStringAsync().Result;
            //            var result = JsonConvert.DeserializeObject<IEnumerable<IdentityProvider>>(json);

        }
Example #6
0
        public void ApplyQuizResult(QuizResult quizResult, Card card, int year, int month, int day)
        {
            // Set current card values on QuizResult so it can be reversed
            quizResult.CardLevel = card.Level >= 0 ? card.Level : 0;
            quizResult.CardQuizDate = card.QuizDate;
            quizResult.CardIsCorrect = card.IsCorrect;
            quizResult.CardCompletedQuizYear = card.CompletedQuizYear;
            quizResult.CardCompletedQuizMonth = card.CompletedQuizMonth;
            quizResult.CardCompletedQuizDay = card.CompletedQuizDay;

            card.Level = quizResult.IsCorrect
                ? card.Level + 1
                : 0;

            if(card.Level < 0) card.Level = 0;

            var daysQuizExtended = this.QuizCalendar.GetQuizInterval(card.Level);
            card.QuizDate = new DateTime(year, month, day).AddDays(daysQuizExtended);
            card.IsCorrect = quizResult.IsCorrect;
            card.CompletedQuizYear = year;
            card.CompletedQuizMonth = month;
            card.CompletedQuizDay = day;
        }
Example #7
0
        public HttpResponseMessage Post(Card card)
        {
            if (this.ModelState.IsValid)
            {
                var clientDateTime = this.GetClientDateTime();
                var quizCalendar = this.TableStorageContext.UserConfigurations.GetByNameIdentifier().QuizCalendar;
                this.TableStorageContext.Cards.Add(card, clientDateTime.AddDays(quizCalendar[0]));
                this.TableStorageContext.CardDecks.AddCardToCardDeck(card);
                this.TableStorageContext.CommitBatch();
                var response = this.Request.CreateResponse(HttpStatusCode.Created, card);

                var routeValues = new
                {
                    controller = this.ControllerContext.ControllerDescriptor.ControllerName,
                    userId = card.UserId,
                    cardId = card.EntityId
                };

                response.Headers.Location = new Uri(this.GetLink(RouteNames.API_CARDS, routeValues));
                return response;
            }

            throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
        }
Example #8
0
        public HttpResponseMessage Put(Card card)
        {
            if (this.ModelState.IsValid)
            {
                this.TableStorageContext.UpdateCardAndRelations(card);
                this.TableStorageContext.Commit();

                return this.Request.CreateResponse(HttpStatusCode.OK, card);
            }

            throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));
        }
 public override void When()
 {
     this.card = new Card { PartitionKey = TestValues.CARD_PARTITION_KEY, RowKey = TestValues.CARD_ROW_KEY };
     this.CardRepository.Setup(x => x.Get(TestValues.CARD_PARTITION_KEY, TestValues.CARD_ROW_KEY)).Returns(this.originalCard);
     this.TableStorageContext.UpdateCardAndRelations(this.card);
 }
        public void CardsController_CRUD()
        {
            const string POST_QUESTION_TEXT = "Created From Unit Test";
            const string PUT_QUESTION_TEXT = "Updated From Unit Test";

            var container = IoC.Initialize();
            var config = new HttpConfiguration { DependencyResolver = new StructureMapWebApiResolver(container),  };
            config.Formatters.Add(new XmlMediaTypeFormatterWrapper());
            config.Formatters.Add(new JsonMediaTypeFormatterWrapper());
            //            config.Formatters.JsonFormatter.MediaTypeMappings.Add(new UriPathExtensionMapping("json", "application/json"));
            //            config.Formatters.XmlFormatter.MediaTypeMappings.Add(new UriPathExtensionMapping("xml", "application/xml"));

            WebApiConfig.Configure(config);

            var server = new HttpServer(config);
            var client = new HttpClient(server);
            client.DefaultRequestHeaders.Add(HttpHeaders.X_CLIENT_DATE, DateTime.Now.ToLongDateString());
            client.DefaultRequestHeaders.Add(HttpHeaders.X_TEST, "true");

            var card = new Card { Question = POST_QUESTION_TEXT, QuizDate = DateTime.Now };

            // Test POST
            // -------------------------------------------------------------------------------------
            var postResponse = client.PostAsJsonAsync(TestUrls.CARDS, card).Result;
            var xx = postResponse.Content.ReadAsStringAsync().Result;
            var postCard = postResponse.Content.ReadAsAsync<Card>().Result;

            // Assert that the POST succeeded
            postResponse.StatusCode.Should().Be(HttpStatusCode.Created);

            // Assert that the posted Card was returned in the response
            postCard.Question.Should().Be(POST_QUESTION_TEXT);

            // Assert that the relevant keys were set on the Card
            postCard.PartitionKey.Should().NotBeEmpty();
            postCard.RowKey.Should().NotBeEmpty();

            // Assert that the location of the new Card was returned in the Location header
            var cardUrl = postResponse.Headers.Location;
            cardUrl.AbsoluteUri.Should().BeEquivalentTo(string.Format("{0}/{1}/{2}", TestUrls.CARDS, postCard.UserId, postCard.EntityId));

            // Test PUT
            // -------------------------------------------------------------------------------------
            postCard.Question = PUT_QUESTION_TEXT;
            var putResponse = client.PutAsJsonAsync(TestUrls.CARDS, postCard).Result;

            // Assert that the PUT succeeded
            putResponse.StatusCode.Should().Be(HttpStatusCode.OK);

            // Test GET
            // -------------------------------------------------------------------------------------
            var getResponse = client.GetAsync(cardUrl).Result;
            var getCard = getResponse.Content.ReadAsAsync<Card>().Result;

            // Assert that the correct Card was returned
            getCard.RowKey.Should().Be(postCard.RowKey);

            // Assert that the PUT did actually update the Card
            getCard.Question.Should().Be(PUT_QUESTION_TEXT);

            // Test DELETE
            // -------------------------------------------------------------------------------------
            var requestMessage = new HttpRequestMessage(HttpMethod.Delete, cardUrl);
            var cardJson = JsonConvert.SerializeObject(new[] { getCard });
            requestMessage.Content = new StringContent(cardJson);
            requestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("text/json");
            var deleteResponse = client.SendAsync(requestMessage).Result;

            // Assert that the DELETE succeeded
            deleteResponse.StatusCode.Should().Be(HttpStatusCode.NoContent);

            // Assert that the Card is no longer in storage
            getResponse = client.GetAsync(cardUrl).Result;
            getResponse.IsSuccessStatusCode.Should().Be(false);
        }
        public void QuizResultsController_CRUD()
        {
            var quizDate = new DateTime(2012, 6, 30);

            var container = IoC.Initialize();
            var config = new HttpConfiguration { DependencyResolver = new StructureMapWebApiResolver(container) };
            config.Formatters.JsonFormatter.MediaTypeMappings.Add(new UriPathExtensionMapping("json", "application/json"));
            config.Formatters.XmlFormatter.MediaTypeMappings.Add(new UriPathExtensionMapping("xml", "application/xml"));

            WebApiConfig.Configure(config);

            var server = new HttpServer(config);
            var client = new HttpClient(server);
            client.DefaultRequestHeaders.Add(HttpHeaders.X_CLIENT_DATE, DateTime.Now.ToLongDateString());
            client.DefaultRequestHeaders.Add(HttpHeaders.X_TEST, "true");

            // Create the card
            var card = new Card { Question = "Created from QuizResultsController_CRUD test.", QuizDate = DateTime.Now };
            var postCardResponse = client.PostAsJsonAsync(TestUrls.CARDS, card).Result;
            var postCard = postCardResponse.Content.ReadAsAsync<Card>().Result;
            var cardUrl = postCardResponse.Headers.Location;

            // Create the QuizResult
            var quizResult = new QuizResult { IsCorrect = true };

            // Test POST
            // -------------------------------------------------------------------------------------
            var testUrl = string.Format(TestUrls.QUIZ_RESULTS, postCard.UserId, quizDate.Year, quizDate.Month, quizDate.Day, postCard.EntityId);
            var postResponse = client.PostAsJsonAsync(testUrl, quizResult).Result;
            var postQuizResult = postResponse.Content.ReadAsAsync<QuizResult>().Result;

            // Assert that the POST succeeded
            postResponse.StatusCode.Should().Be(HttpStatusCode.Created);

            // Assert that the posted QuizResult was returned in the response
            postQuizResult.QuizDate.Should().Be(quizDate);

            // Assert that the relevant fields were set on the QuizResult
            postQuizResult.PartitionKey.Should().NotBeEmpty();
            postQuizResult.RowKey.Should().NotBeEmpty();
            postQuizResult.QuizDate.Should().Be(quizDate);
            postQuizResult.CardId.Should().Be(postCard.EntityId);

            // Assert that the location of the new QuizResult was returned in the Location header
            var quizResultUrl = postResponse.Headers.Location;
            quizResultUrl.AbsoluteUri.Should().BeEquivalentTo(testUrl);

            // Test DELETE
            // -------------------------------------------------------------------------------------
            var deleteResponse = client.DeleteAsync(quizResultUrl).Result;

            // Assert that the DELETE succeeded
            deleteResponse.StatusCode.Should().Be(HttpStatusCode.NoContent);

            // Assert that the Card is no longer in storage
            var getResponse = client.GetAsync(quizResultUrl).Result;
            getResponse.IsSuccessStatusCode.Should().Be(false);

            // Delete the card
            var requestMessage = new HttpRequestMessage(HttpMethod.Delete, cardUrl);
            var cardJson = JsonConvert.SerializeObject(card);
            requestMessage.Content = new StringContent(cardJson);
            requestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("text/json");
            client.SendAsync(requestMessage);

            //            client.DeleteAsync(cardUrl);
        }
 public override void When()
 {
     this.card = new Card { CreatedTimestamp = this.createdTimestamp };
     this.TableStorageRepository.Update(this.card);
 }
 public override void When()
 {
     this.TableStorageContext.Setup(x => x.Cards.GetById(TestValues.USER_ID, TestValues.CARD_ID)).Returns(this.expectedResult);
     this.actualResult = this.CardsController.Get(TestValues.USER_ID, TestValues.CARD_ID);
 }
 public override void When()
 {
     this.card = this.CardRepository.GetByPartitionKey(TestValues.CARD_PARTITION_KEY, TestValues.CARD_ID);
 }
        public override void When()
        {
            this.quizResult = new QuizResult { IsCorrect = true };
            this.card = new Card
            {
                Level = CARD_LEVEL,
                QuizDate = TestValues.CARD_QUIZ_DATE,
                IsCorrect = false,
                CompletedQuizYear = TestValues.YEAR,
                CompletedQuizMonth = TestValues.MONTH,
                CompletedQuizDay = TestValues.DAY
            };

            this.QuizResultHandler.ApplyQuizResult(this.quizResult, this.card, TestValues.CARD_QUIZ_DATE.Year, TestValues.CARD_QUIZ_DATE.Month, TestValues.CARD_QUIZ_DATE.Day);
        }
Example #16
0
 public override void When()
 {
     var userConfiguration = new UserConfiguration { QuizInterval0 = TestValues.INT };
     this.TableStorageContext.Setup(x => x.UserConfigurations.GetByNameIdentifier()).Returns(userConfiguration);
     this.Request.Headers.Add(HttpHeaders.X_CLIENT_DATE, TestValues.DATETIME.ToString("o"));
     this.card = new Card { RowKey = TestValues.ROW_KEY };
     this.response = this.CardsController.Post(this.card);
 }
Example #17
0
 public override void Given()
 {
     this.Card = new Card();
 }
 public override void When()
 {
     this.card = new Card { Timestamp = TestValues.DATETIME };
     this.TableStorageRepository.Update(this.card);
 }
 public override void When()
 {
     this.card = this.CardRepository.GetById(TestValues.USER_ID, TestValues.CARD_ID);
 }