Exemplo n.º 1
0
        public void AcquireTopParameter(string parameterName, string parameterValue, bool parameterValueIsInt, int expectedResult)
        {
            var resource = new HistoryResource();

            var storeMock = new Mock<IReadOnlyPersistenceStore>();
            var contextMock = new Mock<IResourceContext>();
            string output = parameterValue;
            contextMock.Setup(c => c.Parameters.TryGetValue(parameterName, out output)).Returns(parameterValueIsInt);
            contextMock.Setup(c => c.PersistenceStore).Returns(storeMock.Object);

            resource.Execute(contextMock.Object);

            storeMock.Verify(s=>s.GetTop(expectedResult));
        }
Exemplo n.º 2
0
        public void ReturnCacheResourceResultWithData()
        {
            var resource = new HistoryResource();

            var storeMock = new Mock<IReadOnlyPersistenceStore>();
            storeMock.Setup(s => s.GetTop(It.IsAny<int>())).Returns(Enumerable.Empty<GlimpseRequest>());
            var contextMock = new Mock<IResourceContext>();
            string output = "25";
            contextMock.Setup(c => c.Parameters.TryGetValue("top", out output)).Returns(true);
            contextMock.Setup(c => c.PersistenceStore).Returns(storeMock.Object);

            var result = resource.Execute(contextMock.Object);
             
            Assert.NotNull(result as CacheControlDecorator);
        }
Exemplo n.º 3
0
        public void Return404StatusCodeWithoutData()
        {
            var resource = new HistoryResource();

            var storeMock = new Mock<IReadOnlyPersistenceStore>();
            storeMock.Setup(s => s.GetTop(It.IsAny<int>())).Returns<IEnumerable<GlimpseRequest>>(null);
            var contextMock = new Mock<IResourceContext>();
            string output = "25";
            contextMock.Setup(c => c.Parameters.TryGetValue("top", out output)).Returns(true);
            contextMock.Setup(c => c.PersistenceStore).Returns(storeMock.Object);

            var result = resource.Execute(contextMock.Object);

            var statusCodeResult = result as StatusCodeResourceResult;

            Assert.NotNull(statusCodeResult);
            Assert.Equal(404, statusCodeResult.StatusCode);
        }
Exemplo n.º 4
0
        public void ThrowExceptionWithNullContext()
        {
            var resource = new HistoryResource();

            Assert.Throws<ArgumentNullException>(()=>resource.Execute(null));
        }
Exemplo n.º 5
0
        public void ShouldHaveProperName()
        {
            var resource = new HistoryResource();

            Assert.Equal("glimpse_history", resource.Name);
        }
Exemplo n.º 6
0
        public void ContainATopParameter()
        {
            var resource = new HistoryResource();

            Assert.Equal("top", resource.Parameters.First().Name);
        }