public void InsertUpdateUIConfigs() { GeneralSettings genS = new GeneralSettings(); genS.CloudStorageConnectionString = _fixture.Configuratuion.GetSection("General").GetSection("CloudStorageConnectionString").Value.ToString(); //Need to Mock the injected services and setup any properties on these that the test requires var errorSettingsMoq = new Moq.Mock <IOptions <ErrorSettings> >(); var generalSettingsMoq = new Moq.Mock <IOptions <GeneralSettings> >(); generalSettingsMoq.SetupGet(p => p.Value.CloudStorageConnectionString).Returns(genS.CloudStorageConnectionString); var environmentMoq = new Moq.Mock <IHostingEnvironment>(); environmentMoq.SetupGet(p => p.WebRootPath).Returns(@"C:\Repos\mcfork\tree\master\cloud\\src\solution\Microsoft.Legal.MatterCenter.Web\wwwroot"); var matterCenterServiceFunctionsMoq = new Moq.Mock <IMatterCenterServiceFunctions>(); var uiConfigsMoq = new Moq.Mock <IOptions <UIConfigSettings> >(); uiConfigsMoq.SetupGet(t => t.Value.MatterCenterConfiguration).Returns("MatterCenterConfiguration"); uiConfigsMoq.SetupGet(p => p.Value.Partitionkey).Returns("MatterCenterConfig"); uiConfigsMoq.SetupGet(c => c.Value.ConfigGroup).Returns("ConfigGroup"); uiConfigsMoq.SetupGet(k => k.Value.Key).Returns("Key"); uiConfigsMoq.SetupGet(v => v.Value.Value).Returns("Value"); var logTableMoq = new Moq.Mock <IOptions <LogTables> >(); ConfigRepository configRepository = new ConfigRepository(null, generalSettingsMoq.Object, uiConfigsMoq.Object); generalSettingsMoq.SetupGet(g => g.Value).Returns(genS); errorSettingsMoq.SetupAllProperties(); ConfigController controller = new ConfigController(errorSettingsMoq.Object, generalSettingsMoq.Object, uiConfigsMoq.Object, logTableMoq.Object, matterCenterServiceFunctionsMoq.Object, configRepository, environmentMoq.Object); var configsStr = (@"{""Home"": { ""ContextualHelpHeader"": ""Matter Center For Outlook"", ""ContextualHelpBottomText"": ""Questions? Contact "", ""HelpRequesURL"": ""https://msmatter.sharepoint.com/sites/catalog"", ""MatterCenterSupportLinkText"": ""Matter Center Aisling Support"", ""MatterCenterSupportLink"": ""mailto:[email protected]"", ""Change"": ""mailto:[email protected]"", }, ""MatterUsers"": { ""SearchUsersURL"": ""https://msmatter.sharepoint.com/sites/client"", ""StampedPropertiesURL"": ""https://msmatter.sharepoint.com/sites/microsoft"", ""Add"": ""test"", }}"); var result = controller.InsertUpdate(configsStr); Assert.True(result.Status > 0); }
public async void TestSave_Create_Delete() { var moq = new Moq.Mock <IAmazonDynamoDB>(); moq.SetupAllProperties(); moq.Setup(s => s.DeleteItemAsync(It.IsAny <DeleteItemRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new DeleteItemResponse { HttpStatusCode = System.Net.HttpStatusCode.OK }); moq.Setup(s => s.PutItemAsync(It.IsAny <PutItemRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new PutItemResponse { HttpStatusCode = System.Net.HttpStatusCode.OK }); moq.Setup(s => s.QueryAsync(It.IsAny <QueryRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new QueryResponse { HttpStatusCode = System.Net.HttpStatusCode.OK, }); var recipeService = new DynamoRecipeService(moq.Object); var recipe = new Recipe() { Name = "Test Recipe", LastUpdateTime = DateTime.UtcNow, UserId = "123", RecipeId = 456, CookTimeMins = 11, PrepTimeMins = 22, Servings = 99 }; try { var saved = await recipeService.SaveRecipe(recipe); Assert.True(saved); //var retrieved = await recipeService.RetrieveRecipe(recipe.UserId, recipe.RecipeId); //var equal = recipe.Equals(retrieved); //Assert.True(equal); } finally { //var deleted = await recipeService.DeleteRecipe(recipe); //Assert.True(deleted); } }
public void GetConfigsFromTableRep() { GeneralSettings genS = new GeneralSettings(); genS.CloudStorageConnectionString = _fixture.Configuratuion.GetSection("General").GetSection("CloudStorageConnectionString").Value.ToString(); var m = new Moq.Mock <IOptions <GeneralSettings> >(); var l = new Moq.Mock <IOptions <UIConfigSettings> >(); m.SetupGet(g => g.Value).Returns(genS); m.SetupAllProperties(); ConfigRepository configRepository = new ConfigRepository(null, m.Object, l.Object); var response = configRepository.GetConfigEntities(""); }
public void GetAllUIConfigsForSPO() { GeneralSettings genS = new GeneralSettings(); genS.CloudStorageConnectionString = _fixture.Configuratuion.GetSection("General").GetSection("CloudStorageConnectionString").Value.ToString(); //Need to Mock the injected services and setup any properties on these that the test requires var errorSettingsMoq = new Moq.Mock <IOptions <ErrorSettings> >(); var generalSettingsMoq = new Moq.Mock <IOptions <GeneralSettings> >(); generalSettingsMoq.SetupGet(p => p.Value.CloudStorageConnectionString).Returns(genS.CloudStorageConnectionString); generalSettingsMoq.SetupGet(p => p.Value.AdminUserName).Returns(_fixture.Configuratuion.GetSection("General").GetSection("AdminUserName").Value.ToString()); generalSettingsMoq.SetupGet(p => p.Value.AdminPassword).Returns(_fixture.Configuratuion.GetSection("General").GetSection("AdminPassword").Value.ToString()); generalSettingsMoq.SetupGet(p => p.Value.CentralRepositoryUrl).Returns("https://msmatter.sharepoint.com/sites/catalog"); var environmentMoq = new Moq.Mock <IHostingEnvironment>(); environmentMoq.SetupGet(p => p.WebRootPath).Returns(@"C:\projects\mc2\tree\master\cloud\src\solution\Microsoft.Legal.MatterCenter.Web\wwwroot"); var matterCenterServiceFunctionsMoq = new Moq.Mock <IMatterCenterServiceFunctions>(); var uiConfigsMoq = new Moq.Mock <IOptions <UIConfigSettings> >(); uiConfigsMoq.SetupGet(t => t.Value.MatterCenterConfiguration).Returns("MatterCenterConfiguration"); uiConfigsMoq.SetupGet(p => p.Value.Partitionkey).Returns("MatterCenterConfig"); uiConfigsMoq.SetupGet(c => c.Value.ConfigGroup).Returns("ConfigGroup"); uiConfigsMoq.SetupGet(k => k.Value.Key).Returns("Key"); uiConfigsMoq.SetupGet(v => v.Value.Value).Returns("Value"); var logTableMoq = new Moq.Mock <IOptions <LogTables> >(); ConfigRepository configRepository = new ConfigRepository(null, generalSettingsMoq.Object, uiConfigsMoq.Object); generalSettingsMoq.SetupGet(g => g.Value).Returns(genS); errorSettingsMoq.SetupAllProperties(); ConfigController controller = new ConfigController(errorSettingsMoq.Object, generalSettingsMoq.Object, uiConfigsMoq.Object, logTableMoq.Object, matterCenterServiceFunctionsMoq.Object, configRepository, environmentMoq.Object); var result = controller.GetConfigsForSPO(""); Assert.True(result.Status > 0); }
private static Mock<ISummary> GetMocSummary() { var mocSummary = new Moq.Mock<ISummary>(); mocSummary.SetupAllProperties(); mocSummary.Object.TotalNumberOfPassengers = 12; mocSummary.Object.AdjustedTicketRevenue = 123; mocSummary.Object.CanFlightProceed = true; mocSummary.Object.InvalidInput = false; mocSummary.Object.LoyaltyPointsRedeemed = 12; mocSummary.Object.NumberOfAirlinePassengers = 3; mocSummary.Object.NumberOfBags = 12; mocSummary.Object.NumberOfGeneralPassengers = 8; mocSummary.Object.NumberOfLoyaltyPassengers = 1; mocSummary.Object.TotalCostOfFlight = 445; mocSummary.Object.UnadjustedTicketRevenue = 322; return mocSummary; }
private static Mock <ISummary> GetMocSummary() { var mocSummary = new Moq.Mock <ISummary>(); mocSummary.SetupAllProperties(); mocSummary.Object.TotalNumberOfPassengers = 12; mocSummary.Object.AdjustedTicketRevenue = 123; mocSummary.Object.CanFlightProceed = true; mocSummary.Object.InvalidInput = false; mocSummary.Object.LoyaltyPointsRedeemed = 12; mocSummary.Object.NumberOfAirlinePassengers = 3; mocSummary.Object.NumberOfBags = 12; mocSummary.Object.NumberOfGeneralPassengers = 8; mocSummary.Object.NumberOfLoyaltyPassengers = 1; mocSummary.Object.TotalCostOfFlight = 445; mocSummary.Object.UnadjustedTicketRevenue = 322; return(mocSummary); }
public void Suggestionns_GetSuggestion_CheckRelevanceBoundariesAndCorrectness() { // setup var resultMock1 = new Moq.Mock<ISuggestionInstance>(); resultMock1.Setup(r => r.GetTextValue()).Returns("one"); resultMock1.SetupAllProperties(); resultMock1.Object.Rank = 1; var resultMock2 = new Moq.Mock<ISuggestionInstance>(); resultMock2.Setup(r => r.GetTextValue()).Returns("two"); resultMock2.SetupAllProperties(); resultMock2.Object.Rank = 2; var resultMock3 = new Moq.Mock<ISuggestionInstance>(); resultMock3.Setup(r => r.GetTextValue()).Returns("three"); resultMock1.SetupAllProperties(); resultMock1.Object.Rank = 2; var resultMock4 = new Moq.Mock<ISuggestionInstance>(); resultMock4.Setup(r => r.GetTextValue()).Returns("four"); resultMock1.SetupAllProperties(); resultMock1.Object.Rank = 3; var resultMock5 = new Moq.Mock<ISuggestionInstance>(); resultMock5.Setup(r => r.GetTextValue()).Returns("five"); resultMock1.SetupAllProperties(); resultMock1.Object.Rank = 4; var resultMock6 = new Moq.Mock<ISuggestionInstance>(); resultMock6.Setup(r => r.GetTextValue()).Returns("six"); resultMock1.SetupAllProperties(); resultMock1.Object.Rank = 5; this.kernel.Bind<ISuggestionInstance>().ToMethod(s => resultMock1.Object); this.kernel.Bind<ISuggestionInstance>().ToMethod(s => resultMock2.Object); this.kernel.Bind<ISuggestionInstance>().ToMethod(s => resultMock3.Object); this.kernel.Bind<ISuggestionInstance>().ToMethod(s => resultMock4.Object); this.kernel.Bind<ISuggestionInstance>().ToMethod(s => resultMock5.Object); this.kernel.Bind<ISuggestionInstance>().ToMethod(s => resultMock6.Object); // Setup two sources var guid1 = Guid.NewGuid(); var sourceMock1 = new Moq.Mock<ISuggestionSource>(); sourceMock1.Setup(m => m.GetSuggestions(It.IsAny<ISemanticObject>())).Returns(new ISuggestionInstance[] { resultMock3.Object, resultMock2.Object, resultMock4.Object, resultMock5.Object }); sourceMock1.Setup(m => m.Guid).Returns(guid1); var guid2 = Guid.NewGuid(); var sourceMock2 = new Moq.Mock<ISuggestionSource>(); sourceMock2.Setup(m => m.GetSuggestions(It.IsAny<ISemanticObject>())).Returns(new ISuggestionInstance[] { resultMock1.Object, resultMock2.Object, resultMock6.Object }); sourceMock2.Setup(m => m.Guid).Returns(guid2); this.kernel.Bind<ISuggestionSource>().ToMethod(s => sourceMock1.Object); this.kernel.Bind<ISuggestionSource>().ToMethod(s => sourceMock2.Object); // test var sut = this.kernel.Get<Suggester>(); var mockKeyword = this.kernel.GetMock<ISemanticObject>(); var result = sut.GetSuggestions(new ISemanticObject[] { mockKeyword.Object }); Assert.That(result, Is.All.Matches((ISuggestionInstance s) => s.Rank >= 0), "Rank for one or more elements out of range."); Assert.That(result, Is.All.Matches((ISuggestionInstance s) => (s.Relevance <= 100 || s.Relevance >= 0)), "Relevance for one or more elements out of range."); }