示例#1
0
        public static void Create_Many_Should_Works()
        {
            // arrange
            var mongoClient = FakeMongoClient.GetMongoClientMock <GenericTestWithIdProperty>(true).Object;
            var mongoCRUD   = new MongoCRUD <GenericTestWithIdProperty>(mongoClient, "SomeDB");

            var document1 = new GenericTestWithIdProperty
            {
                Id       = "123",
                SomeTest = "test"
            };

            var document2 = new GenericTestWithIdProperty
            {
                Id       = "124",
                SomeTest = "test2"
            };

            var documents = new List <GenericTestWithIdProperty> {
                document1, document2
            };

            // act
            mongoCRUD.Create(documents);

            // assert
            // if no exception, create has success
        }
示例#2
0
        public static void Get_Should_Throws_Exception_When_Id_Is_Null()
        {
            // arrange
            var mongoClient = FakeMongoClient.GetMongoClientMock <GenericTestWithIdProperty>(true).Object;
            var mongoCRUD   = new MongoCRUD <GenericTestWithIdProperty>(mongoClient, "SomeDB");

            // act
            Exception ex =
                Assert.Throws <ArgumentNullException>(() => mongoCRUD.Get(null));

            // assert
            Assert.Equal("Value cannot be null.\r\nParameter name: id", ex.Message);
        }
示例#3
0
        public static void DeleteByQuery_Should_Works_With_Null_Filter()
        {
            // arrange
            var mongoClient = FakeMongoClient.GetMongoClientMock <GenericTestWithIdProperty>(true).Object;
            var mongoCRUD   = new MongoCRUD <GenericTestWithIdProperty>(mongoClient, "SomeDB");
            FilterDefinition <GenericTestWithIdProperty> filters = null;

            // act
            var isAcknowledged = mongoCRUD.DeleteByQuery(filters);

            // assert
            Assert.True(isAcknowledged);
        }
示例#4
0
        public static void DeleteByQuery_Should_Works_With_Filter()
        {
            // arrange
            var mongoClient = FakeMongoClient.GetMongoClientMock <GenericTestWithIdProperty>(true).Object;
            var mongoCRUD   = new MongoCRUD <GenericTestWithIdProperty>(mongoClient, "SomeDB");
            var filters     = FilterBuilder.GetFilterBuilder <GenericTestWithIdProperty>().Eq(r => r.SomeTest, "test");

            // act
            var isAcknowledged = mongoCRUD.DeleteByQuery(filters);

            // assert
            Assert.True(isAcknowledged);
        }
示例#5
0
        public static void Delete_Should_Works()
        {
            // arrange
            var mongoClient = FakeMongoClient.GetMongoClientMock <GenericTestWithIdProperty>(true).Object;
            var mongoCRUD   = new MongoCRUD <GenericTestWithIdProperty>(mongoClient, "SomeDB");
            var id          = "123";

            // act
            var isAcknowledged = mongoCRUD.Delete(id);

            // assert
            Assert.True(isAcknowledged);
        }
示例#6
0
        public static void Upsert_Should_Throws_Exception_When_Document_Is_Null()
        {
            // arrange
            var mongoClient = FakeMongoClient.GetMongoClientMock <GenericTestWithBsonIdAnnotation>(true).Object;
            var mongoCRUD   = new MongoCRUD <GenericTestWithBsonIdAnnotation>(mongoClient, "SomeDB");
            GenericTestWithBsonIdAnnotation document = null;

            // act
            Exception ex =
                Assert.Throws <ArgumentNullException>(() => mongoCRUD.Upsert(document));

            // assert
            Assert.Equal("Value cannot be null.\r\nParameter name: document", ex.Message);
        }
示例#7
0
        public static void Create_Many_Should_Throws_Exception_When_Document_Is_Null()
        {
            // arrange
            var mongoClient = FakeMongoClient.GetMongoClientMock <GenericTestWithIdProperty>(true).Object;
            var mongoCRUD   = new MongoCRUD <GenericTestWithIdProperty>(mongoClient, "SomeDB");
            List <GenericTestWithIdProperty> documents = null;

            // act
            Exception ex =
                Assert.Throws <ArgumentNullException>(() => mongoCRUD.Create(documents));

            // assert
            Assert.Equal("Value cannot be null.\r\nParameter name: documents", ex.Message);
        }
示例#8
0
        public static void Upsert_Should_Works()
        {
            // arrange
            var mongoClient = FakeMongoClient.GetMongoClientMock <GenericTestWithBsonIdAnnotation>(true).Object;
            var mongoCRUD   = new MongoCRUD <GenericTestWithBsonIdAnnotation>(mongoClient, "SomeDB");
            var document    = new GenericTestWithBsonIdAnnotation
            {
                CustomId = "123",
                SomeTest = "test"
            };

            // act
            var isAcknowledged = mongoCRUD.Upsert(document);

            // assert
            Assert.True(isAcknowledged);
        }
示例#9
0
        public static void UpdateByQuery_Should_Works_With_Null_Filter()
        {
            // arrange
            var mongoClient = FakeMongoClient.GetMongoClientMock <GenericTestWithIdProperty>(true).Object;
            var mongoCRUD   = new MongoCRUD <GenericTestWithIdProperty>(mongoClient, "SomeDB");
            var document    = new
            {
                Id       = "123",
                SomeTest = "test"
            };

            // act
            var isAcknowledged = mongoCRUD.UpdateByQuery(null, document);

            // assert
            Assert.True(isAcknowledged);
        }
示例#10
0
        public static void GetDocumentId_Should_Throws_Exception_When_Object_Not_Have_Id_Property_Or_BsonId_Annotation()
        {
            // arrange
            var mongoClient = FakeMongoClient.GetMongoClientMock <GenericTestWithoutIdPropertyOrBsonIdAnnotation>(true).Object;
            var mongoCRUD   = new MongoCRUD <GenericTestWithoutIdPropertyOrBsonIdAnnotation>(mongoClient, "SomeDB");
            var document    = new GenericTestWithoutIdPropertyOrBsonIdAnnotation
            {
                CustomId = "123",
                SomeTest = "some test"
            };

            // act
            Exception ex =
                Assert.Throws <InvalidOperationException>(() => mongoCRUD.Update(document));

            // assert
            Assert.Equal("Model must have a property called 'Id' or a property with BsonId attribute", ex.Message);
        }