public override void When() { this.expectedResult = new UserConfiguration { PartitionKey = TestValues.PARTITION_KEY, RowKey = TestValues.ROW_KEY }; var userConfigurations = new HashSet<UserConfiguration> { this.expectedResult, new UserConfiguration() }.AsQueryable(); this.TableStorageContext.Setup(x => x.CreateQuery<UserConfiguration>()).Returns(userConfigurations); this.actualResult = this.TableStorageRepository.GetOrCreate(TestValues.PARTITION_KEY, TestValues.ROW_KEY); }
public override void Given() { var cards = Builder<Card>.CreateListOfSize(5) .TheFirst(3).With(x => x.PartitionKey = TestValues.CARD_PARTITION_KEY) .TheFirst(1).And(x => x.RowKey = TestValues.CARD_ROW_KEY) .Build(); this.TableStorageContext = new Mock<ITableStorageContext> { DefaultValue = DefaultValue.Mock }; this.TableStorageContext.Setup(x => x.CreateQuery<Card>()).Returns(cards.AsQueryable()); var userConfiguration = new UserConfiguration { UserId = TestValues.USER_ID }; this.TableStorageContext .Setup(x => x.UserConfigurations.GetByNameIdentifier()) .Returns(userConfiguration); this.CardKeyGenerator = new Mock<ICardEntityKeyGenerator>(); this.CardKeyGenerator.Setup(x => x.GeneratePartitionKey(TestValues.USER_ID)).Returns(TestValues.CARD_PARTITION_KEY); this.CardKeyGenerator.Setup(x => x.GenerateRowKey()).Returns(TestValues.CARD_ROW_KEY); this.CardKeyGenerator.Setup(x => x.GetPartitionKey(TestValues.USER_ID)).Returns(TestValues.CARD_PARTITION_KEY); this.CardKeyGenerator.Setup(x => x.GetRowKey(TestValues.CARD_ID)).Returns(TestValues.CARD_ROW_KEY); this.CardKeyGenerator.SetupGet(x => x.GeneratedEntityId).Returns(TestValues.CARD_ID); this.CardRepository = new CardRepository( this.TableStorageContext.Object, this.CardKeyGenerator.Object, TestValues.NAME_IDENTIFIER); }
public override void Given() { this.AuthenticationHelper = new Mock<IAuthenticationHelper>(); this.AuthenticationHelper.SetupGet(x => x.NameIdentifier).Returns(TestValues.NAME_IDENTIFIER); this.TableStorageContext = new Mock<ITableStorageContext> { DefaultValue = DefaultValue.Mock }; var tableStorageContextFactory = new TableStorageContextFactoryMockBuilder() .SetTableStorageContext(this.TableStorageContext) .Build(); this.UserConfiguration = new UserConfiguration { QuizInterval0 = 1, QuizInterval1 = 6, QuizInterval2 = 24, QuizInterval3 = 66, QuizInterval4 = 114, QuizInterval5 = 246 }; this.TableStorageContext .Setup(x => x.UserConfigurations.GetByNameIdentifier()) .Returns(this.UserConfiguration); this.QuizResultHandler = new QuizResultHandler(tableStorageContextFactory.Object, this.AuthenticationHelper.Object); }
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); }
public override void When() { this.TableStorageContext .Setup(x => x.UserConfigurations.GetByNameIdentifier()) .Returns(this.expectedResult); this.actualResult = this.ConfigController.Get(); }
public override void When() { this.userConfiguration = new UserConfiguration(); this.TableStorageContext .Setup(x => x.UserConfigurations.Update(this.userConfiguration)) .Callback<UserConfiguration>(x => x.UserId = TestValues.USER_ID); this.response = this.ConfigController.Put(this.userConfiguration); }
public override void When() { this.matchingUserConfiguration = new UserConfiguration { PartitionKey = TestValues.CARD_PARTITION_KEY, RowKey = TestValues.CONFIGURATION_ROW_KEY }; var nonMatchingUserConfiguration1 = new UserConfiguration { PartitionKey = "Non-matchingPartitionKey", RowKey = TestValues.CONFIGURATION_ROW_KEY }; var nonMatchingUserConfiguration2 = new UserConfiguration { PartitionKey = TestValues.CARD_PARTITION_KEY, RowKey = "Non-matchingRowKey" }; var userConfigurations = new[] { this.matchingUserConfiguration, nonMatchingUserConfiguration1, nonMatchingUserConfiguration2 }; this.TableStorageContext.Setup(x => x.CreateQuery<UserConfiguration>()).Returns(userConfigurations.AsQueryable()); this.userConfiguration = this.UserConfigurationRepository.GetByNameIdentifier(); }
public override void Given() { this.TableStorageContext = new Mock<ITableStorageContext> { DefaultValue = DefaultValue.Mock }; var userConfiguration = new UserConfiguration { UserId = TestValues.USER_ID }; this.TableStorageContext .Setup(x => x.UserConfigurations.GetByNameIdentifier()) .Returns(userConfiguration); this.TableStorageRepository = new TableStorageRepository<Card>(this.TableStorageContext.Object); }
public override void When() { var randomGenerator = new RandomGenerator(); var userConfigurations = Builder<UserConfiguration>.CreateListOfSize(5) .All().With(x => x.RowKey = string.Format("{0}-{1}", CardRowTypes.CONFIGURATION, randomGenerator.Next())) .Random(1).With(x => x.RowKey = TestValues.CONFIGURATION_ROW_KEY) .Build(); this.TableStorageContext.Setup(x => x.CreateQuery<UserConfiguration>()).Returns(userConfigurations.AsQueryable()); this.UserConfigurationKeyGenerator.Setup(x => x.GetRowKey(TestValues.CONFIGURATION_ID)).Returns(TestValues.CONFIGURATION_ROW_KEY); this.userConfiguration = this.UserConfigurationRepository.GetByUserId(TestValues.CONFIGURATION_ID); }
public HttpResponseMessage Put(UserConfiguration userConfiguration) { if (this.ModelState.IsValid) { this.TableStorageContext.UserConfigurations.Update(userConfiguration); this.TableStorageContext.Commit(); return this.Request.CreateResponse(HttpStatusCode.OK, userConfiguration); } throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)); }
public override void Given() { this.TableStorageContext = new Mock<ITableStorageContext> { DefaultValue = DefaultValue.Mock }; var tableStorageContextFactory = new TableStorageContextFactoryMockBuilder() .SetTableStorageContext(this.TableStorageContext, AzureTableNames.CARD, NameIdentifiers.MASTER) .Build(); var userConfiguration = new UserConfiguration { PartitionKey = TestValues.PARTITION_KEY, RowKey = string.Format("{0}-{1}", CardRowTypes.CONFIGURATION, TestValues.USER_ID) }; this.TableStorageContext.Setup(x => x.UserConfigurations.GetByUserId(TestValues.USER_ID)).Returns(userConfiguration); this.LibraryController = new CardsController(tableStorageContextFactory.Object); }
public override void Given() { this.QuizResultKeyGenerator = new Mock<ICardEntityKeyGenerator>(); this.QuizResultKeyGenerator.Setup(x => x.GeneratePartitionKey(TestValues.USER_ID)).Returns(TestValues.PARTITION_KEY); this.QuizResultKeyGenerator.Setup(x => x.GenerateRowKey()).Returns(TestValues.ROW_KEY); this.QuizResultKeyGenerator.SetupGet(x => x.GeneratedEntityId).Returns(TestValues.QUIZ_RESULT_ID); this.TableStorageContext = new Mock<ITableStorageContext> { DefaultValue = DefaultValue.Mock }; var userConfiguration = new UserConfiguration { UserId = TestValues.USER_ID }; this.TableStorageContext .Setup(x => x.UserConfigurations.GetByNameIdentifier()) .Returns(userConfiguration); this.QuizResultsRepository = new QuizResultsRepository( this.TableStorageContext.Object, this.QuizResultKeyGenerator.Object, TestValues.NAME_IDENTIFIER); }
public UserConfiguration CreateUserConfiguration() { var userId = this.identityQueueManager.GetNextIdentity(); var configuration = new UserConfiguration { PartitionKey = string.Format("{0}-{1}", this.authenticationHelper.NameIdentifier, userId), RowKey = string.Format("{0}-{1}", CardRowTypes.CONFIGURATION, userId), UserId = userId, QuizInterval0 = defaultQuizCalendar[0], QuizInterval1 = defaultQuizCalendar[1], QuizInterval2 = defaultQuizCalendar[2], QuizInterval3 = defaultQuizCalendar[3], QuizInterval4 = defaultQuizCalendar[4], QuizInterval5 = defaultQuizCalendar[5] }; return configuration; }
public override void Given() { var authenticationHelper = new Mock<IAuthenticationHelper>(); authenticationHelper.Setup(x => x.NameIdentifier).Returns(TestValues.NAME_IDENTIFIER); this.UserConfiguration = new UserConfiguration { UserId = USER_ID }; var tableStorageContext = new Mock<ITableStorageContext> { DefaultValue = DefaultValue.Mock }; tableStorageContext.Setup(x => x.UserConfigurations.GetByNameIdentifier()).Returns(this.UserConfiguration); this.TableStorageContextFactory = new TableStorageContextFactoryMockBuilder() .SetTableStorageContext(tableStorageContext) .Build(); this.IdentityQueueManager = new Mock<IIdentityQueueManager>(); this.IdentityQueueManager.Setup(x => x.GetNextIdentity()).Returns(NEXT_IDENTITY_VALUE); this.CardKeyGenerator = new CardEntityKeyGenerator( authenticationHelper.Object, this.IdentityQueueManager.Object, CardRowTypes.CARD); }
public override void When() { this.quizDate = new DateTime(TestValues.YEAR, TestValues.MONTH, TestValues.DAY); var dayBefore = this.quizDate.AddDays(-TestValues.DAY); var millisecondAfter = this.quizDate.AddMilliseconds(TestValues.DAY); var twelveHoursAfter = this.quizDate.AddHours(12); var dayAfter = this.quizDate.AddDays(TestValues.DAY); var generator = new UniqueRandomGenerator(); // Use EntityId of >= 100 to indicate which cards should be included in result var userCards = Builder<Card>.CreateListOfSize(10) .All().With(x => x.CreatedTimestamp = generator.Next(DateTime.MinValue, DateTime.MaxValue)) .TheFirst(2).With(x => x.QuizDate = dayBefore).And(x => x.EntityId = generator.Next(100, 1000)) .TheNext(2).With(x => x.QuizDate = this.quizDate).And(x => x.EntityId = generator.Next(100, 1000)) .TheNext(2).With(x => x.QuizDate = millisecondAfter).And(x => x.EntityId = generator.Next(100, 1000)) .TheNext(2).With(x => x.QuizDate = twelveHoursAfter).And(x => x.EntityId = generator.Next(100, 1000)) .TheNext(2).With(x => x.QuizDate = dayAfter) .Build(); this.quizResultCards = Builder<Card>.CreateListOfSize(2) .All().With(x => x.EntityId = generator.Next(100, 1000)) .Build(); // Use IsCorrect = true to indicate which cards should be included in result this.quizResults = Builder<QuizResult>.CreateListOfSize(3).Build(); this.TableStorageContext.Setup(x => x.Cards.GetForUser()).Returns(userCards.AsQueryable()); this.TableStorageContext.Setup(x => x.Cards.GetForQuizResults(this.quizResults)).Returns(this.quizResultCards.AsQueryable()); this.TableStorageContext.Setup(x => x.QuizResults.GetForQuiz(TestValues.YEAR, TestValues.MONTH, TestValues.DAY)).Returns(this.quizResults.AsQueryable()); var userConfiguration = new UserConfiguration { UserId = TestValues.USER_ID }; this.TableStorageContext.Setup(x => x.UserConfigurations.GetByNameIdentifier()).Returns(userConfiguration); this.cards = this.CardsController.GetForQuiz(TestValues.YEAR, TestValues.MONTH, TestValues.DAY); }
public override void When() { this.IdentityQueueManager.Setup(x => x.GetNextIdentity()).Returns(NEXT_IDENTITY_VALUE); this.userConfiguration = this.UserHelper.CreateUserConfiguration(); }
public override void When() { this.TableStorageContext.Setup(x => x.CreateQuery<UserConfiguration>()).Returns(new Collection<UserConfiguration>().AsQueryable()); this.result = this.TableStorageRepository.GetOrCreate(TestValues.PARTITION_KEY, TestValues.ROW_KEY); }
public override void When() { this.userConfiguration = new UserConfiguration(); this.ConfigController.ModelState.AddModelError("Error Key", "Error Message"); this.ConfigController.Put(this.userConfiguration); }