示例#1
0
        public void PostWithoutUserNameReturnsCorrectResponse()
        {
            var projectionStub = new Mock <IUserNameProjection>();
            var queryDummy     = new Mock <IJournalEntriesQuery>();
            var cmdMock        = new Mock <IAddJournalEntryCommand>();
            var sut            = new JournalController(
                projectionStub.Object,
                queryDummy.Object,
                cmdMock.Object)
            {
                Request = new HttpRequestMessage()
            };

            sut.Request.Properties.Add(
                HttpPropertyKeys.HttpConfigurationKey,
                new HttpConfiguration());

            projectionStub
            .Setup(p => p.GetUserName(It.IsAny <HttpRequestMessage>()))
            .Returns((string)null);

            var dummyEntry = new JournalEntryModel();

            var response = sut.Post(dummyEntry);

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
            cmdMock.Verify(
                c => c.AddJournalEntry(It.IsAny <JournalEntryModel>(), It.IsAny <string>()),
                Times.Never);
        }
示例#2
0
        public void PostInsertsEntry(string userName)
        {
            var projectionStub = new Mock <IUserNameProjection>();
            var queryDummy     = new Mock <IJournalEntriesQuery>();
            var cmdMock        = new Mock <IAddJournalEntryCommand>();
            var sut            = new JournalController(
                projectionStub.Object,
                queryDummy.Object,
                cmdMock.Object)
            {
                Request = new HttpRequestMessage()
            };

            sut.Request.Properties.Add(
                HttpPropertyKeys.HttpConfigurationKey,
                new HttpConfiguration());

            projectionStub.Setup(p => p.GetUserName(sut.Request)).Returns(userName);

            var entry = new JournalEntryModel();

            sut.Post(entry);

            cmdMock.Verify(c => c.AddJournalEntry(entry, userName));
        }
示例#3
0
        public void GettingJournalEntriesAfterPostingReturnsPostedJournalEntry()
        {
            var controller = new JournalController();
            var expected   = new JournalEntry
            {
                Time     = DateTimeOffset.Now,
                Distance = 5000,
                Duration = TimeSpan.FromMinutes(24)
            };

            controller.Post(expected);
            var actual = controller.Get();

            Assert.Equal(new JournalEntry[] { expected }, actual);
        }
示例#4
0
        public void PostingAJournalEntryCreatesAJournalEntry()
        {
            var controller = new JournalController();
            var server     = new TestServer(new WebHostBuilder().UseStartup <Startup>());
            var expected   = new JournalEntry
            {
                Time     = DateTimeOffset.Now,
                Distance = 5000,
                Duration = TimeSpan.FromMinutes(24)
            };

            var result = controller.Post(expected);

            Assert.IsType <JournalEntry>(result);
            Assert.Equal(expected, result);
        }
        public void PostInsertsEntry(string userName)
        {
            var projectionStub = new Mock<IUserNameProjection>();
            var queryDummy = new Mock<IJournalEntriesQuery>();
            var cmdMock = new Mock<IAddJournalEntryCommand>();
            var sut = new JournalController(
                projectionStub.Object,
                queryDummy.Object,
                cmdMock.Object)
            {
                Request = new HttpRequestMessage()
            };
            sut.Request.Properties.Add(
                HttpPropertyKeys.HttpConfigurationKey,
                new HttpConfiguration());

            projectionStub.Setup(p => p.GetUserName(sut.Request)).Returns(userName);

            var entry = new JournalEntryModel();
            sut.Post(entry);

            cmdMock.Verify(c => c.AddJournalEntry(entry, userName));
        }
        public void PostWithoutUserNameReturnsCorrectResponse()
        {
            var projectionStub = new Mock<IUserNameProjection>();
            var queryDummy = new Mock<IJournalEntriesQuery>();
            var cmdMock = new Mock<IAddJournalEntryCommand>();
            var sut = new JournalController(
                projectionStub.Object,
                queryDummy.Object,
                cmdMock.Object)
            {
                Request = new HttpRequestMessage()
            };
            sut.Request.Properties.Add(
                HttpPropertyKeys.HttpConfigurationKey,
                new HttpConfiguration());

            projectionStub
                .Setup(p => p.GetUserName(It.IsAny<HttpRequestMessage>()))
                .Returns((string)null);

            var dummyEntry = new JournalEntryModel();

            var response = sut.Post(dummyEntry);

            Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
            cmdMock.Verify(
                c => c.AddJournalEntry(It.IsAny<JournalEntryModel>(), It.IsAny<string>()),
                Times.Never);
        }