Example #1
0
        public void ShouldDeleteData()
        {
            // Arrange
            var testRepo             = new MongoDbSslRepository(_connectionString, _dbName);
            var collection           = testRepo.MongoDatabase.GetCollection <MongoDbSslData <IProcessManagerData> >(_testCollectionName);
            IProcessManagerData data = new TestDataSsl {
                CorrelationId = _correlationId, Name = "TestData"
            };

            collection.InsertOne(new MongoDbSslData <IProcessManagerData> {
                Data = data
            });
            IProcessManagerFinder processManagerFinder = new MongoDbSslProcessManagerFinder(_connectionString, _dbName);

            // Act
            processManagerFinder.DeleteData(new MongoDbSslData <IProcessManagerData> {
                Data = data
            });

            // Assert
            var collection2 = testRepo.MongoDatabase.GetCollection <MongoDbSslData <TestDataSsl> >(_testCollectionName);
            var filter      = Builders <MongoDbSslData <TestDataSsl> > .Filter.Eq(_ => _.Data.CorrelationId, _correlationId);

            var deletedData = collection2.Find(filter).FirstOrDefault();

            Assert.Null(deletedData);
        }
Example #2
0
        public void ShouldUpdateData()
        {
            // Arrange
            var testRepo             = new MongoDbSslRepository(_connectionString, _dbName);
            IProcessManagerData data = new TestDataSsl {
                CorrelationId = _correlationId, Name = "TestData"
            };
            var collection  = testRepo.MongoDatabase.GetCollection <MongoDbSslData <IProcessManagerData> >(_testCollectionName);
            var versionData = new MongoDbSslData <IProcessManagerData> {
                Data = data
            };

            collection.InsertOne(versionData);
            ((TestDataSsl)data).Name = "TestDataUpdated";
            IProcessManagerFinder processManagerFinder = new MongoDbSslProcessManagerFinder(_connectionString, _dbName);

            // Act
            processManagerFinder.UpdateData(versionData);

            // Assert
            var collection2 = testRepo.MongoDatabase.GetCollection <MongoDbSslData <TestDataSsl> >(_testCollectionName);
            var filter      = Builders <MongoDbSslData <TestDataSsl> > .Filter.Eq(_ => _.Data.CorrelationId, _correlationId);

            var updatedData = collection2.Find(filter).First();

            Assert.Equal("TestDataUpdated", updatedData.Data.Name);
            Assert.Equal(1, updatedData.Version);
        }
Example #3
0
        public void ShouldInsertData()
        {
            // Arrange
            IProcessManagerData data = new TestDataSsl {
                CorrelationId = _correlationId, Name = "TestData"
            };
            IProcessManagerFinder processManagerFinder = new MongoDbSslProcessManagerFinder(_connectionString, _dbName);

            // Act
            processManagerFinder.InsertData(data);

            // Assert
            var testRepo   = new MongoDbSslRepository(_connectionString, _dbName);
            var collection = testRepo.MongoDatabase.GetCollection <MongoDbSslData <TestDataSsl> >(_testCollectionName);
            var filter     = Builders <MongoDbSslData <TestDataSsl> > .Filter.Eq(_ => _.Data.CorrelationId, _correlationId);

            var insertedData = collection.Find(filter).First();

            Assert.Equal("TestData", insertedData.Data.Name);
        }
Example #4
0
        public void ShouldFindData()
        {
            // Arrange
            var testRepo             = new MongoDbSslRepository(_connectionString, _dbName);
            IProcessManagerData data = new TestDataSsl {
                CorrelationId = _correlationId, Name = "TestData"
            };
            IMongoCollection <MongoDbSslData <IProcessManagerData> > collection = testRepo.MongoDatabase.GetCollection <MongoDbSslData <IProcessManagerData> >(_testCollectionName);

            collection.InsertOne(new MongoDbSslData <IProcessManagerData> {
                Data = data
            });
            IProcessManagerFinder processManagerFinder = new MongoDbSslProcessManagerFinder(_connectionString, _dbName);

            // Act
            var result = processManagerFinder.FindData <TestDataSsl>(_mapper, new Message(_correlationId));

            // Assert
            Assert.Equal("TestData", result.Data.Name);
        }
Example #5
0
        public void ShouldThrowWhenUpdatingTwoInstancesOfSameDataAtTheSameTime()
        {
            // Arrange
            var testRepo = new MongoDbSslRepository(_connectionString, _dbName);
            IProcessManagerData data1 = new TestDataSsl {
                CorrelationId = _correlationId, Name = "TestData1"
            };
            var collection = testRepo.MongoDatabase.GetCollection <MongoDbSslData <IProcessManagerData> >(_testCollectionName);

            collection.InsertOne(new MongoDbSslData <IProcessManagerData> {
                Data = data1
            });
            IProcessManagerFinder processManagerFinder = new MongoDbSslProcessManagerFinder(_connectionString, _dbName);

            var foundData1 = processManagerFinder.FindData <TestDataSsl>(_mapper, new Message(_correlationId));
            var foundData2 = processManagerFinder.FindData <TestDataSsl>(_mapper, new Message(_correlationId));

            processManagerFinder.UpdateData(foundData1); // first update should be fine

            // Act / Assert
            Assert.Throws <ArgumentException>(() => processManagerFinder.UpdateData(foundData2)); // second update should fail
        }