public void InsertContent_Success() { // Arrange var helpCssLink = "Test CSS Link"; var helpHtml = "Test HTML"; var documentPart1 = "<html><he"; var documentPart2 = "ad>{0}Hea"; var documentPart3 = "d Content</head><body>Body Content{1}</b"; var documentPart4 = "ody></html>"; var responseStream = new MemoryStream(); var htmlBuilder = Mocks.Create <IHtmlBuilder>(); htmlBuilder.Setup(b => b.CreateFirstTimeHelpCssLink()).Returns(helpCssLink); htmlBuilder.Setup(b => b.CreateFirstTimeHelpHtml()).Returns(helpHtml); var filter = new HttpResponseFilter(responseStream, htmlBuilder.Object); // Act filter.Write(Encoding.UTF8.GetBytes(documentPart1), 0, documentPart1.Length); filter.Write(Encoding.UTF8.GetBytes(documentPart2.Replace("{0}", string.Empty)), 0, documentPart2.Length - 3); filter.Write(Encoding.UTF8.GetBytes(documentPart3.Replace("{1}", string.Empty)), 0, documentPart3.Length - 3); filter.Write(Encoding.UTF8.GetBytes(documentPart4), 0, documentPart4.Length); filter.Flush(); // Assert responseStream.Position = 0; var responseReader = new StreamReader(responseStream); var response = responseReader.ReadToEnd(); Assert.That(response, Is.EqualTo(string.Format(documentPart1 + documentPart2 + documentPart3 + documentPart4, helpCssLink, helpHtml)), "The response should have had the correct content inserted at the correct locations."); }
public void Process_Success() { // Arrange var tempPath = TestContext.CurrentContext.TestDirectory; var tempFile = Path.Combine(tempPath, ContentFileConstants.ContentFileName); var path = Mocks.Create <IPath>(); path.Setup(p => p.MapPath("~")).Returns(tempPath); var helpContentManager = Mocks.Create <IHelpContentManager>(); helpContentManager.Setup(m => m.ExportContent(tempFile)); var testFileContent = "Test File Content"; File.WriteAllText(tempFile, testFileContent); var processor = new GenerateInstallScriptRequestProcessor(path.Object, helpContentManager.Object); // Act var result = processor.Process(null); // Assert Assert.That(result, Is.Not.Null, "A valid response state should be returned."); Assert.That(result.Content, Is.EqualTo(testFileContent), "The response should contain the text of the content file."); Assert.That(result.ContentType, Is.EqualTo(ContentTypes.Text), "The content type is plain text."); Assert.That(result.Disposition.Contains(string.Format("filename={0}", ContentFileConstants.ContentFileName)), Is.True, "The response disposition should be set correctly."); if (File.Exists(tempFile)) { File.Delete(tempFile); } }
public void Process_Success() { // Arrange var page = Models.CreateDocumentationPage(id: 84932); var pageRepository = Mocks.Create <IDocumentationPageRepository>(); pageRepository.Setup(r => r.Read(page.Id)).Returns(page); var processor = new ReadDocumentationPageRequestProcessor(pageRepository.Object); // Act var result = processor.Process(page.Id.ToString()); // Assert Assert.That(result, Is.Not.Null, "A valid ResponseState should be returned."); Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK), "The request should succeed."); Assert.That(result.ContentType, Is.EqualTo(ContentTypes.Json), "JSON should be returned in the response."); var serializer = new JavaScriptSerializer(); var clientPage = serializer.Deserialize <DocumentationPage>(result.Content); Assert.That(clientPage.Id, Is.EqualTo(page.Id), "The page read from the repository should be included in the result."); Mocks.VerifyAll(); }
public void Process_ExistingPage() { // Arrange var dataStorePage = Models.CreateDocumentationPage(id: 84926); var clientPage = new DocumentationPage { Id = dataStorePage.Id, // Same id as data store page because this is an existing page. Title = dataStorePage.Title, Content = dataStorePage.Content, Order = dataStorePage.Order, ParentPageId = dataStorePage.ParentPageId, }; var documentationPageRepository = Mocks.Create <IDocumentationPageRepository>(); documentationPageRepository.Setup(r => r.Read(clientPage.Id)).Returns(dataStorePage); documentationPageRepository.Setup(r => r.Update(It.Is <DocumentationPage>(p => p.Id == clientPage.Id))); var serializer = new JavaScriptSerializer(); var requestData = serializer.Serialize(clientPage); var processor = new SaveDocumentationPageRequestProcessor(documentationPageRepository.Object); // Act var result = processor.Process(requestData); // Assert Assert.That(result, Is.Not.Null, "A response state instance should be returned."); Assert.That(result.ContentType, Is.EqualTo(ContentTypes.Json), "The response content should contain JSON."); var resultPage = serializer.Deserialize <DocumentationPage>(result.Content); Assert.That(resultPage.Id, Is.EqualTo(clientPage.Id), "The page id should not change."); Mocks.VerifyAll(); }
public void Process_NewPage() { // Arrange var clientHelp = Models.CreateFirstTimeHelp(); var clientBullet = Models.CreateBullet(clientHelp.Id); clientHelp.Bullets.Add(clientBullet); var helpRepository = Mocks.Create <IFirstTimeHelpRepository>(); helpRepository.Setup(r => r.Create(It.Is <FirstTimeHelp>(p => p.Title == clientHelp.Title))); var bulletRepository = Mocks.Create <IBulletRepository>(); bulletRepository.Setup(r => r.Create(It.Is <Bullet>(b => b.Text == clientBullet.Text))); var serializer = new JavaScriptSerializer(); var requestData = serializer.Serialize(clientHelp); var processor = new SaveFirstTimeHelpRequestProcessor(bulletRepository.Object, helpRepository.Object); // Act var result = processor.Process(requestData); // Assert Mocks.VerifyAll(); Assert.That(result, Is.Not.Null, "Response state instance expected."); Assert.That(result.ContentType, Is.EqualTo(ContentTypes.Json), "JSON result expected."); Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK), "Valid response code expected."); var resultPage = serializer.Deserialize <FirstTimeHelp>(result.Content); Assert.That(resultPage.Title, Is.EqualTo(clientHelp.Title), "The title of the result page should match the client page."); Assert.That(resultPage.Bullets.Count, Is.EqualTo(clientHelp.Bullets.Count), "The page returned should have the same number of bullets as the original client page."); }
public void Process_Success() { // Arrange var isAuthorized = true; Configuration.DocumentationConfiguration.Setup(c => c.Disabled).Returns(true); var editAuthorizer = Mocks.Create <IEditAuthorizer>(); editAuthorizer.Setup(a => a.Authorize()).Returns(isAuthorized); var processor = new ReadApplicationSettingsRequestProcessor(Configuration.Object, editAuthorizer.Object); // Act var result = processor.Process(null); // Assert Assert.That(result, Is.Not.Null, "A valid ResponseState should be returned."); Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK), "The request should succeed."); Assert.That(result.ContentType, Is.EqualTo(ContentTypes.Json), "JSON should be returned."); var serializer = new JavaScriptSerializer(); var settings = serializer.Deserialize <ApplicationSettings>(result.Content); Assert.That(settings.CanEdit, Is.EqualTo(isAuthorized), "The JSON result should contain the edit authorization result."); Assert.That(settings.DisableDocumentation, Is.True, "Documentation should be disabled in the JSON result."); Mocks.VerifyAll(); }
public void ProcessRequestInternal_ContentNotFound() { // Arrange var requestProcessor = Mocks.Create <IRequestProcessor>(); requestProcessor.Setup(p => p.Process(ItemId)).Returns(new ResponseState { StatusCode = HttpStatusCode.NotFound }); var notFoundProcessor = Mocks.Create <IRequestProcessor>(); notFoundProcessor.Setup(p => p.Process(null)).Returns(new ResponseState { StatusCode = HttpStatusCode.NotFound, Content = "404" }); RequestProcessorFactory.Setup(f => f.Create(MethodName)).Returns(requestProcessor.Object); RequestProcessorFactory.Setup(f => f.Create(RequestTypes.NotFound)).Returns(notFoundProcessor.Object); var handler = new HttpHandler(Container.Object); // Act handler.ProcessRequestInternal(HttpContext.Object); // Assert Mocks.VerifyAll(); }
public void AttachFilterEventHandler_AttachToCompatibleHandler(string handlerAssemblyName, string handlerTypeName) { // Arrange var container = Mocks.Create <IContainer>(); container.Setup(c => c.Resolve <IHtmlBuilder>()).Returns(Mocks.Create <IHtmlBuilder>().Object); var response = Mocks.Create <HttpResponseBase>(); response.Setup(r => r.ContentType).Returns(ContentTypes.Html); response.Setup(r => r.Filter).Returns(new MemoryStream()); response.SetupSet(r => r.Filter = It.IsAny <HttpResponseFilter>()); var handlerAssembly = Assembly.Load(handlerAssemblyName); var handlerType = handlerAssembly.GetType(handlerTypeName); var handler = (IHttpHandler)Activator.CreateInstance(handlerType, new RequestContext()); var context = Mocks.Create <HttpContextBase>(); context.Setup(c => c.Items.Contains(HttpModule.ContainerKey)).Returns(false); context.Setup(c => c.Items.Add(HttpModule.ContainerKey, true)); context.Setup(c => c.CurrentHandler).Returns(handler); context.Setup(c => c.Response).Returns(response.Object); var module = new HttpModule(context.Object, container.Object, null, null); // Act module.AttachFilterEventHandler(null, null); // Assert Mocks.VerifyAll(); }
public void Process_ExistingPage() { // Arrange var dataStorePage = Models.CreateFirstTimeHelp(id: 84926); var dataStoreBullets = new List <Bullet>(); dataStoreBullets.Add(Models.CreateBullet(id: 54829, pageId: dataStorePage.Id)); dataStoreBullets.Add(Models.CreateBullet(id: 29334, pageId: dataStorePage.Id)); var updatedBullet = dataStoreBullets[0]; var deletedBullet = dataStoreBullets[1]; var clientHelp = new FirstTimeHelp { Id = dataStorePage.Id, // Same id as data store page because this is an existing page. Title = dataStorePage.Title, Content = dataStorePage.Content, }; clientHelp.Bullets.Add(Models.CreateBullet(clientHelp.Id)); clientHelp.Bullets.Add(dataStoreBullets[0]); var newBullet = clientHelp.Bullets[0]; var helpRepository = Mocks.Create <IFirstTimeHelpRepository>(); helpRepository.Setup(r => r.Update(It.Is <FirstTimeHelp>(p => p.Id == clientHelp.Id))); var bulletRepository = Mocks.Create <IBulletRepository>(); bulletRepository.Setup(r => r.ReadByPageId(clientHelp.Id)).Returns(dataStoreBullets); bulletRepository.Setup(r => r.Create(It.Is <Bullet>(b => b.Text == newBullet.Text))); bulletRepository.Setup(r => r.Update(It.Is <Bullet>(b => b.Id == updatedBullet.Id))); bulletRepository.Setup(r => r.Delete(deletedBullet.Id)); var serializer = new JavaScriptSerializer(); var requestData = serializer.Serialize(clientHelp); var processor = new SaveFirstTimeHelpRequestProcessor(bulletRepository.Object, helpRepository.Object); // Act var result = processor.Process(requestData); // Assert Assert.That(result, Is.Not.Null, "A response state instance should be returned."); Assert.That(result.ContentType, Is.EqualTo(ContentTypes.Json), "The response content should contain JSON."); var resultHelp = serializer.Deserialize <FirstTimeHelp>(result.Content); Assert.That(resultHelp.Id, Is.EqualTo(clientHelp.Id), "The page id should not change."); Assert.That(resultHelp.Bullets.Count, Is.EqualTo(clientHelp.Bullets.Count), "The returned page should have the same number of bullets as the client page."); foreach (var clientBullet in clientHelp.Bullets) { Assert.That(resultHelp.Bullets.Where(resultBullet => resultBullet.Text == clientBullet.Text).Count(), Is.EqualTo(1), "All bullets in client model should be returned in the result."); } Mocks.VerifyAll(); }
public TestHarness(int taskId = 42) { MockHost = Mocks.Create <PSHost>(); MockUI = Mocks.Create <PSHostUserInterface>(MockBehavior.Loose); MockHost .SetupGet(h => h.UI) .Returns(MockUI.Object); TaskHost = new TaskHost(MockHost.Object, new ConsoleState(), taskId); }
public void CreateDocumentationPageHtml_FirstResponseConfiguredUrls() { // Arrange var titleToken = "[TITLE]"; var jsTreeCssToken = "[JSTREECSS]"; var customCssToken = "[CUSTOMCSS]"; var jQueryUrlToken = "[JQUERYURL]"; var jQueryUiUrlToken = "[JQUERYUIURL]"; var jsTreeUrlToken = "[JSTREEURL]"; var html = string.Concat(titleToken, jsTreeCssToken, customCssToken, jQueryUrlToken, jQueryUiUrlToken, jsTreeUrlToken); var title = "Test Title -"; var jsTreeCss = "jsTree CSS -"; var customCss = "custom CSS - "; var jQueryUrl = "jQuery URL - "; var minifier = Mocks.Create <IMinifier>(); minifier.Setup(m => m.Minify(HtmlContent.Documentation, HtmlContent.Documentation_min)).Returns(html); Configuration.DocumentationConfiguration.Setup(c => c.PageTitle).Returns(title); Configuration.DocumentationConfiguration.Setup(c => c.CustomCss).Returns(customCss); Configuration.DocmahConfiguration.Setup(c => c.CssUrl).Returns(jsTreeCss); Configuration.DocmahConfiguration.Setup(c => c.JsUrl).Returns(jQueryUrl); var memoryCache = Mocks.Create <ObjectCache>(); memoryCache.Setup(c => c.Contains(HtmlBuilder._documentationHtmlCacheKey, null as string)).Returns(false); memoryCache.Setup(c => c.Set(HtmlBuilder._documentationHtmlCacheKey, It.IsAny <string>(), It.IsAny <CacheItemPolicy>(), null as string)); var htmlBuilder = new HtmlBuilder(null, null, Configuration.Object, null, null, memoryCache.Object, minifier.Object, null); // Act var result = htmlBuilder.CreateDocumentationPageHtml(); // Assert Assert.That(result.Contains(titleToken), Is.False, "The title token should be replaced."); Assert.That(result.Contains(jsTreeCssToken), Is.False, "The jsTree CSS token should be replaced."); Assert.That(result.Contains(customCssToken), Is.False, "The custom CSS token should be replaced."); Assert.That(result.Contains(jQueryUrlToken), Is.False, "The jQuery URL token should be replaced."); Assert.That(result.Contains(jQueryUiUrlToken), Is.False, "The jQuery UI URL token should be replaced."); Assert.That(result.Contains(jsTreeUrlToken), Is.False, "The jsTree URL token should be replaced."); Assert.That(result.Contains(title), Is.True, "The configured title should be inserted."); Assert.That(result.Contains(jsTreeCss), Is.True, "The configured jsTree CSS URL should be inserted."); Assert.That(result.Contains(customCss), Is.True, "The configured custom CSS URL should be instered."); Assert.That(result.Contains(jQueryUrl), Is.True, "The configured jQuery URL should be inserted."); Assert.That(result.Contains(CdnUrls.jsJQueryUi), Is.False, "The jQuery UI URL should not be inserted when a custom JS URL is configured."); Assert.That(result.Contains(CdnUrls.jsJsTree), Is.False, "The jsTree URL should not be inserted when a custom JS URL is configured."); Mocks.VerifyAll(); }
public TestHarness(int?taskId = null) { TaskId = taskId ?? Random.Next(); MockUI = Mocks.Create <PSHostUserInterface>(); ConsoleState = new ConsoleState { IsAtBol = Random.NextBool(), LastTaskId = Random.Next() }; TaskHostUI = new TaskHostUI(MockUI.Object, ConsoleState, TaskId); }
public void AttachFilterEventHAndler_AlreadyAttached() { // Arrange var context = Mocks.Create <HttpContextBase>(); context.Setup(c => c.Items.Contains(HttpModule.ContainerKey)).Returns(true); var module = new HttpModule(context.Object, null, null, null); // Act module.AttachFilterEventHandler(null, null); // Assert Mocks.VerifyAll(); }
public void ProcessRequestInternal_NoAuthorization() { // Arrange var requestProcessor = Mocks.Create <IRequestProcessor>(); requestProcessor.Setup(p => p.Process(ItemId)).Returns(new ResponseState()); RequestProcessorFactory.Setup(f => f.Create(MethodName)).Returns(requestProcessor.Object); var handler = new HttpHandler(Container.Object); // Act handler.ProcessRequestInternal(HttpContext.Object); // Assert Mocks.VerifyAll(); }
public void Process_MoveToNewParent() { // Arrange var oldParentPage = Models.CreateDocumentationPage(id: 46382); var newParentPage = Models.CreateDocumentationPage(id: 29556); var oldLowerSibling = Models.CreateDocumentationPage(id: 98732, parentPageId: oldParentPage.Id, order: 0); var targetPage = Models.CreateDocumentationPage(id: 43900, parentPageId: oldParentPage.Id, order: 1); var oldHigherSibling = Models.CreateDocumentationPage(id: 43729, parentPageId: oldParentPage.Id, order: 2); var oldSiblings = new List <DocumentationPage> { oldLowerSibling, targetPage, oldHigherSibling }; var newLowerSibling = Models.CreateDocumentationPage(id: 12943, parentPageId: newParentPage.Id, order: 0); var newHigherSibling = Models.CreateDocumentationPage(id: 84539, parentPageId: newParentPage.Id, order: 1); var newSiblings = new List <DocumentationPage> { newLowerSibling, newHigherSibling }; var pageRepository = Mocks.Create <IDocumentationPageRepository>(); pageRepository.Setup(r => r.Read(targetPage.Id)).Returns(targetPage); pageRepository.Setup(r => r.ReadByParentId(oldParentPage.Id)).Returns(oldSiblings); pageRepository.Setup(r => r.Update(It.Is <DocumentationPage>(p => p.Id == oldHigherSibling.Id && p.Order == 1))); pageRepository.Setup(r => r.ReadByParentId(newParentPage.Id)).Returns(newSiblings); pageRepository.Setup(r => r.Update(It.Is <DocumentationPage>(p => p.Id == targetPage.Id && p.ParentPageId == newParentPage.Id && p.Order == 1))); pageRepository.Setup(r => r.Update(It.Is <DocumentationPage>(p => p.Id == newHigherSibling.Id && p.Order == 2))); var serializer = new JavaScriptSerializer(); var moveRequest = new MoveTocRequest { PageId = targetPage.Id, NewParentId = newParentPage.Id, NewPosition = 1 }; var requestData = serializer.Serialize(moveRequest); var processor = new MovePageRequestProcessor(pageRepository.Object); // Act var result = processor.Process(requestData); // Assert Assert.That(result, Is.Not.Null, "A valid response state instance should be returned."); Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK), "The result status code should be OK."); Assert.That(result.ContentType, Is.EqualTo(ContentTypes.Html), "The result content type should be HTML."); Mocks.VerifyAll(); }
public void Process_Success() { // Arrange var minifier = Mocks.Create <IMinifier>(); minifier.Setup(m => m.Minify(It.IsAny <string>(), It.IsAny <string>())).Returns("Content"); var processor = new JavaScriptRequestProcessor(minifier.Object); // Act var result = processor.Process(string.Empty); // Assert Assert.That(result, Is.Not.Null, "Response data expected."); Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK), "Valid HTTP response code expected."); Assert.That(result.Content, Is.EqualTo("Content"), "Minified content expected."); Assert.That(result.ContentType, Is.EqualTo(ContentTypes.JavaScript), "JavaScript ContentType expected."); }
public void ProcessRequestInternal_InvalidRequestType() { // Arrange var requestProcessor = Mocks.Create <IRequestProcessor>(); requestProcessor.Setup(p => p.Process(ItemId)).Returns(new ResponseState()); RequestProcessorFactory.Setup(f => f.Create(MethodName)).Throws(new InvalidOperationException("Dependency creator not registered")); RequestProcessorFactory.Setup(f => f.Create(RequestTypes.NotFound)).Returns(requestProcessor.Object); var handler = new HttpHandler(Container.Object); // Act handler.ProcessRequestInternal(HttpContext.Object); // Assert Mocks.VerifyAll(); }
public void Create_Success() { // Arrange var requestType = "TestRequestType"; var processor = Mocks.Create <IRequestProcessor>(); var container = Mocks.Create <IContainer>(); container.Setup(c => c.Resolve <IRequestProcessor>(requestType)).Returns(processor.Object); var factory = new RequestProcessorFactory(container.Object); // Act var result = factory.Create(requestType); // Assert Assert.That(result, Is.Not.Null, "A request processor should be returned."); Assert.That(result, Is.SameAs(processor.Object), "The request processor returned should be the mock processor."); container.VerifyAll(); }
public void MarshallerIsCalled() { using (var mocks = new Mocks()) { var marshal = mocks.Create<IMarshal>(); var configuration = new RepositoryConfiguration { Marshal = marshal.Object }; using (var repo = new Repository<Model>(configuration, new ModelFactory<Model>(() => new Model()))) { marshal.Setup(m => m.MarshalQueryResult("result")).Returns("marshal result"); var marshalledResult = repo.Query(m => "result"); Assert.That(marshalledResult, Is.EqualTo("marshal result")); } } }
public void Minify_DebuggerAttached() { // Arrange var debugger = Mocks.Create <IDebugger>(); debugger.Setup(d => d.IsAttached).Returns(true); var fullContent = "full"; var minifiedContent = "minified"; var minifier = new Minifier(debugger.Object, null); // Act var result = minifier.Minify(fullContent, minifiedContent); // Assert Assert.That(result, Is.EqualTo(fullContent), "The content should not be minified because the debugger is attached."); Mocks.VerifyAll(); }
public void CreateDocumentationPageHtml_CachedResponse() { // Arrange var html = "<html><body>This is only a test.</body></html>"; var memoryCache = Mocks.Create <ObjectCache>(); memoryCache.Setup(c => c.Contains(HtmlBuilder._documentationHtmlCacheKey, null as string)).Returns(true); memoryCache.Setup(c => c.Get(HtmlBuilder._documentationHtmlCacheKey, null as string)).Returns(html); var builder = new HtmlBuilder(null, null, null, null, null, memoryCache.Object, null, null); // Act var result = builder.CreateDocumentationPageHtml(); // Assert Assert.That(result, Is.EqualTo(html), "The result should be the HTML returned from the cache."); Mocks.VerifyAll(); }
public void Import_ContentUpToDate() { // Arrange WriteMinimalContentFile(); var lastDataStoreVersion = EnumExtensions.GetMaxValue <DataStoreSchemaVersions>(); var dataStoreConfiguration = Mocks.Create <IDataStoreConfiguration>(MockBehavior.Strict); dataStoreConfiguration.SetupGet(c => c.DataStoreSchemaVersion).Returns((int)lastDataStoreVersion); dataStoreConfiguration.SetupGet(c => c.HelpContentVersion).Returns(1); var helpContentManager = new HelpContentManager(null, dataStoreConfiguration.Object, null, null, null); // Act helpContentManager.ImportContent(_contentFileName); // Assert Mocks.VerifyAll(); }
public void Process_Success() { // Arrange var page = Models.CreateDocumentationPage(id: 66387, order: 1, parentPageId: 23198); var sibling0 = Models.CreateDocumentationPage(id: 98231, order: 0, parentPageId: page.ParentPageId); var sibling2 = Models.CreateDocumentationPage(id: 66123, order: 2, parentPageId: page.ParentPageId); var child0 = Models.CreateDocumentationPage(id: 4392, order: 0, parentPageId: page.Id); var child1 = Models.CreateDocumentationPage(id: 9342, order: 1, parentPageId: page.Id); var siblings = new List <DocumentationPage> { sibling0, page, sibling2 }; var children = new List <DocumentationPage> { child0, child1 }; var pageRepository = Mocks.Create <IDocumentationPageRepository>(); pageRepository.Setup(r => r.Read(page.Id)).Returns(page); pageRepository.Setup(r => r.ReadByParentId(page.ParentPageId)).Returns(siblings); // read to update orders. pageRepository.Setup(r => r.ReadByParentId(page.Id)).Returns(children); // read to update orders and parent id. pageRepository.Setup(r => r.Update(It.Is <DocumentationPage>(p => p.Id == child0.Id && p.ParentPageId == page.ParentPageId && p.Order == 1))); pageRepository.Setup(r => r.Update(It.Is <DocumentationPage>(p => p.Id == child1.Id && p.ParentPageId == page.ParentPageId && p.Order == 2))); pageRepository.Setup(r => r.Update(It.Is <DocumentationPage>(p => p.Id == sibling2.Id && p.ParentPageId == page.ParentPageId && p.Order == 3))); pageRepository.Setup(r => r.Delete(page.Id)); var bulletRepository = Mocks.Create <IBulletRepository>(); bulletRepository.Setup(r => r.DeleteByPageId(page.Id)); var userPageSettingsRepository = Mocks.Create <IUserPageSettingsRepository>(); userPageSettingsRepository.Setup(r => r.DeleteByPageId(page.Id)); var processor = new DeletePageRequestProcessor(bulletRepository.Object, pageRepository.Object, userPageSettingsRepository.Object); // Act var result = processor.Process(page.Id.ToString()); // Assert Assert.That(result, Is.Not.Null, "A Valid ResponseState should be returned."); Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK), "The request should return a valid HTTP status."); }
public void Authorize_Disabled() { // Arrange var httpRequest = Mocks.Create <HttpRequestBase>(); var httpContext = Mocks.Create <HttpContextBase>(); httpContext.Setup(c => c.Request).Returns(httpRequest.Object); Configuration.EditHelpConfiguration.Setup(c => c.IsDisabled).Returns(true); var authorizer = new EditAuthorizer(httpContext.Object, Configuration.Object); // Act var result = authorizer.Authorize(); // Assert Assert.That(result, Is.False, "Authorization should fail because editing is disabled."); Mocks.VerifyAll(); }
public void SetUp() { RequestProcessorFactory = Mocks.Create <IRequestProcessorFactory>(); EditAuthorizer = Mocks.Create <IEditAuthorizer>(); Container = Mocks.Create <IContainer>(); Container.Setup(c => c.Resolve <IRequestProcessorFactory>()).Returns(RequestProcessorFactory.Object); Container.Setup(c => c.Resolve <IEditAuthorizer>()).Returns(EditAuthorizer.Object); // The response writing code would be too cumbersome to setup for every test. // We'll stub this one out and verify in a dedicated test. Response = new Mock <HttpResponseBase>(); Response.Setup(r => r.Cache).Returns(new Mock <HttpCachePolicyBase>().Object); // Likewise, a lot goes on under the hood with the request that is not worth verifying. HttpContext = new Mock <HttpContextBase>(); HttpContext.Setup(c => c.Request.InputStream).Returns(new MemoryStream(Encoding.UTF8.GetBytes(string.Empty))); HttpContext.Setup(c => c.Request["m"]).Returns(MethodName); HttpContext.Setup(c => c.Request["id"]).Returns(ItemId); HttpContext.Setup(c => c.Response).Returns(Response.Object); }
public void Process_Success() { // Arrange var testCss = "Test CSS"; var minifier = Mocks.Create <IMinifier>(); minifier.Setup(m => m.Minify(Resources.DocMAHStyles, Resources.DocMAHStyles_min)).Returns(testCss); var processor = new CssRequestProcessor(minifier.Object); // Act var result = processor.Process(null); // Assert Assert.That(result, Is.Not.Null, "A valid ResponseState should be returned."); Assert.That(result.ContentType, Is.EqualTo(ContentTypes.Css), "The response should contain CSS."); Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK), "The response should be successful."); Assert.That(result.Content, Is.EqualTo(testCss), "The response should contain the content provided by the minifier."); }
public void Process_NotFound() { // Arrange var pageId = 389432; var pageRepository = Mocks.Create <IDocumentationPageRepository>(); pageRepository.Setup(r => r.Read(pageId)).Returns(null as DocumentationPage); var processor = new ReadDocumentationPageRequestProcessor(pageRepository.Object); // Act var result = processor.Process(pageId.ToString()); // Assert Assert.That(result, Is.Not.Null, "A valid ResponseState should be returned."); Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.NotFound)); Mocks.VerifyAll(); }
public void Import_UpdateContent() { // Arrange WriteMinimalContentFile(); var bulletRepository = Mocks.Create <IBulletRepository>(); bulletRepository.Setup(r => r.DeleteExcept(It.IsAny <List <int> >())); var lastDataStoreVersion = EnumExtensions.GetMaxValue <DataStoreSchemaVersions>(); var dataStoreConfiguration = Mocks.Create <IDataStoreConfiguration>(MockBehavior.Strict); dataStoreConfiguration.SetupGet(c => c.DataStoreSchemaVersion).Returns((int)lastDataStoreVersion); dataStoreConfiguration.SetupGet(c => c.HelpContentVersion).Returns(0); dataStoreConfiguration.SetupSet(c => c.HelpContentVersion = 1); var pageRepository = Mocks.Create <IDocumentationPageRepository>(); pageRepository.Setup(r => r.DeleteExcept(It.IsAny <List <int> >())); var helpRepository = Mocks.Create <IFirstTimeHelpRepository>(); helpRepository.Setup(r => r.DeleteExcept(It.IsAny <List <int> >())); var userPageSettingsRepository = Mocks.Create <IUserPageSettingsRepository>(); userPageSettingsRepository.Setup(r => r.DeleteExcept(It.IsAny <List <int> >())); var updater = new HelpContentManager( bulletRepository.Object, dataStoreConfiguration.Object, pageRepository.Object, helpRepository.Object, userPageSettingsRepository.Object); // Act updater.ImportContent(_contentFileName); // Assert Mocks.VerifyAll(); }
public void Process_ChangeParentPage() { // Arrange var dataStorePage = Models.CreateDocumentationPage(id: 75326, parentPageId: 12943, order: 5); var clientPage = Models.CreateDocumentationPage(id: dataStorePage.Id, parentPageId: 543, order: dataStorePage.Order); var serializer = new JavaScriptSerializer(); var requestData = serializer.Serialize(clientPage); var documentationPageRepository = Mocks.Create <IDocumentationPageRepository>(); documentationPageRepository.Setup(r => r.Read(clientPage.Id)).Returns(dataStorePage); var processor = new SaveDocumentationPageRequestProcessor(documentationPageRepository.Object); // Act processor.Process(requestData); // Assert // InvalidOperationException should be thrown. }
public void Process_Success() { // Arrange var testDocumentationContent = "Test documentation content."; Configuration.DocumentationConfiguration.Setup(c => c.Disabled).Returns(false); var htmlBuilder = Mocks.Create <IHtmlBuilder>(); htmlBuilder.Setup(b => b.CreateDocumentationPageHtml()).Returns(testDocumentationContent); var processor = new DocumentationPageRequestProcessor(Configuration.Object, htmlBuilder.Object); // Act var result = processor.Process(null); // Assert Assert.That(result, Is.Not.Null, "A valid ResponseState should be returned."); Assert.That(result.StatusCode, Is.EqualTo(HttpStatusCode.OK), "The request should be successful."); Assert.That(result.ContentType, Is.EqualTo(ContentTypes.Html), "The response should contain HTML."); Assert.That(result.Content, Is.EqualTo(testDocumentationContent), "The response content should contain the HtmlBuilder result."); }
public void Authorize_Success() { // Arrange var httpRequest = Mocks.Create <HttpRequestBase>(); var httpContext = Mocks.Create <HttpContextBase>(); httpContext.Setup(c => c.Request).Returns(httpRequest.Object); Configuration.EditHelpConfiguration.Setup(c => c.IsDisabled).Returns(false); Configuration.EditHelpConfiguration.Setup(c => c.RequireAuthentication).Returns(false); Configuration.EditHelpConfiguration.Setup(c => c.RequireLocalConnection).Returns(false); var authorizer = new EditAuthorizer(httpContext.Object, Configuration.Object); // Act var result = authorizer.Authorize(); // Assert Assert.That(result, Is.True, "Authorization should succeed."); Mocks.VerifyAll(); }