Exemplo n.º 1
0
        public async void Create_MarkSessionModelAlreadyExists_ThrowsException()
        {
            // Arrange
            var existingMarkSessionModel = new MarkSessionModel(
                "be69cb8c-45e4-4d80-8d55-419984aa2151",
                "be69cb8c-45e4-4d80-8d55-419984aa2151",
                ResourceTypeEnum.Project,
                MarkSessionTypeEnum.ToBeDeleted
                );
            var       dbMongoService        = new DbMongoService();
            var       markSessionRepository = new MarkSessionRepository(dbMongoService);
            Exception exception             = null;

            try
            {
                // Act
                await markSessionRepository.Create(existingMarkSessionModel);
            }
            catch (MarkSessionAlreadyExistsException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
        }
        public async void Create_ExistingMarkSessionModel_ThrowsException()
        {
            // Arrange
            var markSessionModel             = MarkSessionModelDataMocks.MockMarkSessionModel();
            var markSessionModelIndexManager = new Mock <IMongoIndexManager <MarkSessionModel> >();

            markSessionModelIndexManager
            .Setup(m => m.CreateOneAsync(
                       It.IsAny <IndexKeysDefinition <MarkSessionModel> >(),
                       It.IsAny <CreateIndexOptions>(),
                       It.IsAny <CancellationToken>()
                       )).ReturnsAsync("");
            var markSessionCollection = new Mock <IMongoCollection <MarkSessionModel> >();

            markSessionCollection
            .Setup(m => m.Indexes)
            .Returns(markSessionModelIndexManager.Object);
            markSessionCollection
            .Setup(m => m.InsertOneAsync(
                       It.IsAny <MarkSessionModel>(),
                       It.IsAny <InsertOneOptions>(),
                       It.IsAny <CancellationToken>()
                       )).Returns(Task.FromException(new Exception()));
            var dbMongoService = new Mock <IDbMongoService>();

            dbMongoService
            .Setup(m => m.GetMarkSessionCollection())
            .Returns(markSessionCollection.Object);
            var       markSessionRepository = new MarkSessionRepository(dbMongoService.Object);
            Exception exception             = null;

            try
            {
                // Act
                await markSessionRepository.Create(markSessionModel);
            }
            catch (FailedToCreateMarkSessionException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
        }