Beispiel #1
0
        public async Task GetByIdAsync_ReturnsDomainBottle_WhenBottleReturnedFromCollection()
        {
            //Arrange

            //Create the Id of the object to retrieve from the mock collection
            var idString = "507f1f77bcf86cd799439011";
            var objectId = new ObjectId(idString);

            var mongoBottleReturnedByCollection = new BottleMongoModel {
                BottleId = objectId, Name = "bottleName"
            };

            var mockCursor = CreateAndSetUpMockCursor(new List <BottleMongoModel> {
                mongoBottleReturnedByCollection
            });
            var mockCollection = CreateAndSetupMockMongoCollection(mockCursor.Object);

            _mockDbContext.SetupGet(c => c.Collection).Returns(mockCollection.Object);


            //Setup the domain Bottle we expect to be returned by the method
            var expectedDomainBottle = new BottleDomainModel {
                BottleId = idString, Name = "bottleName"
            };

            var repo = new BottleMongoRepository(_mockDbContext.Object, _toMongoModelMapper, _toDomainModelMapper);

            //Act
            var result = await repo.GetByIdAsync("507f1f77bcf86cd799439010");

            //Assert
            Assert.AreEqual(expectedDomainBottle.BottleId, result.BottleId);
            Assert.AreEqual(expectedDomainBottle.Name, result.Name);
        }
Beispiel #2
0
        public async Task GetByIdAsync_RetursNull_WhenInvalidIdPassed()
        {
            //Arrange
            var repo = new BottleMongoRepository(_mockDbContext.Object, _toMongoModelMapper, _toDomainModelMapper);

            //Act
            var result = await repo.GetByIdAsync("invalidId");

            //Assert
            Assert.IsNull(result);
        }
Beispiel #3
0
        public async Task GetByIdAsync_ReturnsNull_IfInvalidIdStringPassed()
        {
            //Arrange
            var repo = new BottleMongoRepository(_mockDbContext.Object, _toMongoModelMapper, _toDomainModelMapper);

            //Act
            var result = await repo.GetByIdAsync("1234");

            //Assert
            Assert.AreEqual(null, result);
        }
Beispiel #4
0
        public async Task GetByIdAsync_ReturnsNull_WhenNoBottleIsReturnedFromCollection()
        {
            //Arrange
            var mockCursor     = CreateAndSetUpMockCursor(new List <BottleMongoModel>());
            var mockCollection = CreateAndSetupMockMongoCollection(mockCursor.Object);

            _mockDbContext.SetupGet(c => c.Collection).Returns(mockCollection.Object);

            var repo = new BottleMongoRepository(_mockDbContext.Object, _toMongoModelMapper, _toDomainModelMapper);

            //Act
            var result = await repo.GetByIdAsync("507f1f77bcf86cd799439010");

            //Assert
            Assert.IsNull(result);
        }