public async Task Test7_ReturnsTheMovie()
            {
                GetMocks(out var driverMock, out _, out var transactionMock, out _);

                const string expectedTitle    = "Foo";
                const string expectedTagline  = "Bar";
                const int    expectedReleased = 1900;

                var nodeMock   = GetMockNode(expectedTitle, expectedTagline, expectedReleased);
                var cursorMock = new Mock <IResultCursor>();

                cursorMock.Setup(x => x.Current["m"])
                .Returns(nodeMock.Object);

                cursorMock
                .SetupSequence(x => x.FetchAsync())
                .Returns(Task.FromResult(true))
                .Returns(Task.FromResult(false));

                transactionMock
                .Setup(x => x.RunAsync(It.IsAny <string>(), It.IsAny <object>()))
                .Returns(Task.FromResult(cursorMock.Object));

                var movieStore = new MovieStore(driverMock.Object);
                var movies     = (await movieStore.GetMovie("Valid")).ToList();

                movies.Should().HaveCount(1);
                var movie = movies.First();

                movie.Title.Should().Be(expectedTitle);
                movie.Tagline.Should().Be(expectedTagline);
                movie.Released.Should().Be(expectedReleased);
            }
            public async Task Test5a_AttemptsToGetTheData()
            {
                GetMocks(out var driverMock, out _, out var transactionMock, out _);

                var nodeMock   = GetMockNode();
                var cursorMock = new Mock <IResultCursor>();

                cursorMock.Setup(x => x.Current["m"])
                .Returns(nodeMock.Object);

                cursorMock
                .SetupSequence(x => x.FetchAsync())
                .Returns(Task.FromResult(true))
                .Returns(Task.FromResult(false));

                transactionMock
                .Setup(x => x.RunAsync(It.IsAny <string>(), It.IsAny <object>()))
                .Returns(Task.FromResult(cursorMock.Object));

                var movieStore = new MovieStore(driverMock.Object);
                await movieStore.GetMovie("Valid");

                nodeMock.Verify(x => x.Properties["title"], Times.Once);
                nodeMock.Verify(x => x.Properties["tagline"], Times.Once);
                nodeMock.Verify(x => x.Properties["released"], Times.Once);
            }
            public async Task Test2_UsesTheAsyncSession_ToGetTheMovie()
            {
                GetMocks(out var driverMock, out _, out _, out _);
                var movieStore = new MovieStore(driverMock.Object);
                await movieStore.GetMovie("valid");

                driverMock.Verify(x => x.AsyncSession(), Times.Once);
            }
            public async Task Test1_ReturnsEmptyCollection_WhenInvalidTitleGiven()
            {
                GetMocks(out var driverMock, out _, out _, out _);
                var movieStore = new MovieStore(driverMock.Object);
                var actual     = await movieStore.GetMovie("invalid");

                actual.Should().BeEmpty();
            }
Exemplo n.º 5
0
            public async Task Test2_UsesTheAsyncSession_ToGetTheMovie()
            {
                GetMocks(out var driverMock, out _, out _, out _, out _);
                var movieStore = new MovieStore(driverMock.Object);
                await movieStore.GetMovie_Part2("valid");

                driverMock.Verify(x => x.AsyncSession(It.IsAny <Action <SessionConfigBuilder> >()), Times.Once);
            }
            public async Task Test3_OpensAReadTransaction()
            {
                GetMocks(out var driverMock, out var sessionMock, out _, out _);

                var movieStore = new MovieStore(driverMock.Object);
                await movieStore.GetMovie("valid");

                sessionMock.Verify(x => x.ReadTransactionAsync(It.IsAny <Func <IAsyncTransaction, Task <List <Movie> > > >()), Times.Once);
            }
            public async Task Test5_CallsFetchAsyncToGetTheNextRecord()
            {
                GetMocks(out var driverMock, out _, out _, out var cursorMock);

                var movieStore = new MovieStore(driverMock.Object);
                await movieStore.GetMovie("Valid");

                cursorMock.Verify(x => x.FetchAsync(), Times.Once);
            }
            public async Task Test4a_ExecutesUsingTheRightParameter()
            {
                const string expectedParameter = "valid";

                GetMocks(out var driverMock, out _, out var transactionMock, out _);

                var movieStore = new MovieStore(driverMock.Object);
                await movieStore.GetMovie(expectedParameter);

                transactionMock.Verify(x => x.RunAsync(It.IsAny <string>(), It.Is <object>(o => CompareParameters(o, expectedParameter, "title"))), Times.Once);
            }
            public async Task Test4_ExecutesTheRightCypher()
            {
                const string expectedCypher = "MATCH (m:Movie) WHERE m.title = $title RETURN m";

                GetMocks(out var driverMock, out _, out var transactionMock, out _);

                var movieStore = new MovieStore(driverMock.Object);
                await movieStore.GetMovie("valid");

                transactionMock.Verify(x => x.RunAsync(expectedCypher, It.IsAny <object>()), Times.Once);
            }
Exemplo n.º 10
0
            public async Task Part2_Test1_UsesTheCorrectDatabase()
            {
                const string expectedDb = "movies";

                GetMocks(out var mockDriver, out _, out _, out _, out var builder);
                var movieStore = new MovieStore(mockDriver.Object);
                await movieStore.GetMovie_Part2("Valid");

                var config = builder.Build();

                config.Database.Should().Be(expectedDb);
            }
            public async Task Test6_CallsFetchAsyncUntilFalseReturned()
            {
                GetMocks(out var driverMock, out _, out var transactionMock, out _);

                var nodeMock   = GetMockNode();
                var cursorMock = new Mock <IResultCursor>();

                cursorMock.Setup(x => x.Current["m"])
                .Returns(nodeMock.Object);

                cursorMock
                .SetupSequence(x => x.FetchAsync())
                .Returns(Task.FromResult(true))
                .Returns(Task.FromResult(false));

                transactionMock
                .Setup(x => x.RunAsync(It.IsAny <string>(), It.IsAny <object>()))
                .Returns(Task.FromResult(cursorMock.Object));

                var movieStore = new MovieStore(driverMock.Object);
                await movieStore.GetMovie("Valid");

                cursorMock.Verify(x => x.FetchAsync(), Times.Exactly(2));
            }