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 }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }