Exemplo n.º 1
0
        public async Task AddAsync_WhenCancellationRequestedIsTrue_ThrowsOperationCanceledException()
        {
            if (!IntegrationTestHelper.IsMartenDbRunning)
            {
                return;
            }

            // arrange
            var       cancellationToken = new CancellationToken(true);
            const int newStudentId      = 9;
            var       student           = new Student
            {
                Id        = newStudentId,
                FirstName = "cc",
                LastName  = "dd"
            };

            // act
            var exception = await Record.ExceptionAsync(() => _fixture.SubjectUnderTest.AddAsync(student, cancellationToken));

            // assert
            Assert.NotNull(exception);
            Assert.IsType <OperationCanceledException>(exception);
            Assert.Equal("The operation was canceled.", exception.Message);
        }
Exemplo n.º 2
0
        public async Task AddAsync_AddNewEntity_ReturnsAddedEntity()
        {
            if (!IntegrationTestHelper.IsMartenDbRunning)
            {
                return;
            }

            // arrange
            const int newStudentId = 6;
            var       student      = new Student
            {
                Id        = newStudentId,
                FirstName = "c",
                LastName  = "d"
            };

            // act
            var result = await _fixture.SubjectUnderTest.AddAsync(student);

            var queryResult = await _fixture.SubjectUnderTest.GetByIdAsync(newStudentId);

            // assert
            Assert.NotNull(queryResult);
            Assert.Equal("c", queryResult.FirstName);
            Assert.Equal(result.FirstName, queryResult.FirstName);
        }
Exemplo n.º 3
0
        public async Task StoreAsync_AddNewEntities_ReturnsAddedEntities()
        {
            if (!IntegrationTestHelper.IsMartenDbRunning)
            {
                return;
            }

            var cancellationToken = new CancellationToken(false);
            var userRepository    = _fixture.ServiceProvider.GetService <IRepository <User> >();

            // arrange
            var student = new Student
            {
                Id        = 9,
                FirstName = "a",
                LastName  = "b"
            };

            var user = new User
            {
                Id        = 10,
                FirstName = "c",
                LastName  = "d"
            };

            // act
            await _fixture.SubjectUnderTest.StoreAsync(cancellationToken, student, user);

            var expectedStudent = await _fixture.SubjectUnderTest.GetByIdAsync(9);

            var expectedUser = await userRepository.GetByIdAsync(10);

            // assert
            Assert.NotNull(expectedStudent);
            Assert.NotNull(expectedUser);
        }