diff --git a/Frends.MongoDB.Update/CHANGELOG.md b/Frends.MongoDB.Update/CHANGELOG.md index 921f572..dc11050 100644 --- a/Frends.MongoDB.Update/CHANGELOG.md +++ b/Frends.MongoDB.Update/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [1.0.1] - 2023-11-23 +### Fixed +- Fixed dll error when importing the Task to Frends by adding local dll reference to the project file. + ## [1.0.0] - 2022-11-01 ### Added - Initial implementation \ No newline at end of file diff --git a/Frends.MongoDB.Update/Frends.MongoDB.Update.Tests/Frends.MongoDB.Update.Tests.csproj b/Frends.MongoDB.Update/Frends.MongoDB.Update.Tests/Frends.MongoDB.Update.Tests.csproj index 222a0e2..9e4fec7 100644 --- a/Frends.MongoDB.Update/Frends.MongoDB.Update.Tests/Frends.MongoDB.Update.Tests.csproj +++ b/Frends.MongoDB.Update/Frends.MongoDB.Update.Tests/Frends.MongoDB.Update.Tests.csproj @@ -15,6 +15,12 @@ + + + + + + diff --git a/Frends.MongoDB.Update/Frends.MongoDB.Update.Tests/UnitTests.cs b/Frends.MongoDB.Update/Frends.MongoDB.Update.Tests/UnitTests.cs index 9765ae4..6e0c0a0 100644 --- a/Frends.MongoDB.Update/Frends.MongoDB.Update.Tests/UnitTests.cs +++ b/Frends.MongoDB.Update/Frends.MongoDB.Update.Tests/UnitTests.cs @@ -1,224 +1,254 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Frends.MongoDB.Update.Definitions; -using MongoDB.Bson; -using MongoDB.Driver; -using System; - -namespace Frends.MongoDB.Update.Tests; - -[TestClass] -public class UnitTests -{ - /* - Run command 'docker-compose up -d' in \Frends.MongoDB.Update.Tests\Files\ - */ - - private static readonly Connection _connection = new() - { - ConnectionString = "mongodb://admin:Salakala@localhost:27017/?authSource=admin", - Database = "testdb", - CollectionName = "testcoll", - }; - - private readonly string _doc1 = "{ 'foo':'bar', 'bar': 'foo' }"; - private readonly string _doc2 = "{ 'foo':'bar', 'bar': 'foo' }"; - private readonly string _doc3 = "{ 'qwe':'rty', 'asd': 'fgh' }"; - - - [TestInitialize] - public void StartUp() - { - InsertTestData(); - } - - [TestCleanup] - public void CleanUp() - { - UpdateTestData(); - } - - [TestMethod] - public async Task Test_Update_NotFound() - { - var _input = new Input() - { - InputType = InputType.Filter, - UpdateOptions = Definitions.UpdateOptions.UpdateOne, - Filter = "{'not':'found'}", - Filters = null, - File = null, - UpdateString = "{$set: {foo:'update'}}" - }; - - var result = await MongoDB.Update(_input, _connection, default); - Assert.IsTrue(result.Success.Equals(true) && result.Count == 0); - Assert.IsTrue(GetDocuments("update").Equals(false)); - } - - [TestMethod] - public async Task Test_Update_Single_UpdateOne() - { - var _input = new Input() - { - InputType = InputType.Filter, - UpdateOptions = Definitions.UpdateOptions.UpdateOne, - Filter = "{'foo':'bar'}", - Filters = null, - File = null, - UpdateString = "{$set: {foo:'update'}}" - }; - - var result = await MongoDB.Update(_input, _connection, default); - Assert.IsTrue(result.Success.Equals(true) && result.Count == 1); - Assert.IsTrue(GetDocuments("update").Equals(true)); - } - - [TestMethod] - public async Task Test_Update_Single_UpdateMany() - { - var _input = new Input() - { - InputType = InputType.Filter, - UpdateOptions = Definitions.UpdateOptions.UpdateMany, - Filter = "{'foo':'bar'}", - Filters = null, - File = null, - UpdateString = "{$set: {foo:'update'}}" - }; - - var result = await MongoDB.Update(_input, _connection, default); - Assert.IsTrue(result.Success.Equals(true) && result.Count == 2); - Assert.IsTrue(GetDocuments("update").Equals(true)); - } - - [TestMethod] - public async Task Test_Update_Array_UpdateOne() - { - var doc1 = new DocumentValues() { Value = "{'foo':'bar'}" }; - var doc2 = new DocumentValues() { Value = "{'qwe':'rty'}" }; - - var _input = new Input() - { - InputType = InputType.Filters, - UpdateOptions = Definitions.UpdateOptions.UpdateOne, - Filter = null, - Filters = new[] { doc1, doc2 }, - File = null, - UpdateString = "{$set: {foo:'update'}}" - }; - - var result = await MongoDB.Update(_input, _connection, default); - Assert.IsTrue(result.Success.Equals(true) && result.Count == 2); - Assert.IsTrue(GetDocuments("update").Equals(true)); - } - - [TestMethod] - public async Task Test_Update_Array_UpdateMany() - { - var doc1 = new DocumentValues() { Value = "{'foo':'bar'}" }; - var doc2 = new DocumentValues() { Value = "{'qwe':'rty'}" }; - - var _input = new Input() - { - InputType = InputType.Filters, - UpdateOptions = Definitions.UpdateOptions.UpdateMany, - Filter = null, - Filters = new[] { doc1, doc2 }, - File = null, - UpdateString = "{$set: {foo:'update'}}" - }; - - var result = await MongoDB.Update(_input, _connection, default); - Assert.IsTrue(result.Success.Equals(true) && result.Count == 3); - Assert.IsTrue(GetDocuments("update").Equals(true)); - } - - [TestMethod] - public async Task Test_Update_File_UpdateOne() - { - var _input = new Input() - { - InputType = InputType.File, - UpdateOptions = Definitions.UpdateOptions.UpdateOne, - Filter = null, - Filters = null, - File = "..//..//..//Files//testdata.json", - UpdateString = "{$set: {foo:'update'}}" - }; - - var result = await MongoDB.Update(_input, _connection, default); - Assert.IsTrue(result.Success.Equals(true) && result.Count == 1); - Assert.IsTrue(GetDocuments("update").Equals(true)); - } - - [TestMethod] - public async Task Test_Update_File_UpdateMany() - { - var _input = new Input() - { - InputType = InputType.File, - UpdateOptions = Definitions.UpdateOptions.UpdateMany, - Filter = null, - Filters = null, - File = "..//..//..//Files//testdata.json", - UpdateString = "{$set: {foo:'update'}}" - }; - - var result = await MongoDB.Update(_input, _connection, default); - Assert.IsTrue(result.Success.Equals(true) && result.Count == 2); - Assert.IsTrue(GetDocuments("update").Equals(true)); - } - - private void InsertTestData() - { - try - { - var collection = GetMongoCollection(_connection.ConnectionString, _connection.Database, _connection.CollectionName); - - var doc1 = BsonDocument.Parse(_doc1); - var doc2 = BsonDocument.Parse(_doc2); - var doc3 = BsonDocument.Parse(_doc3); - - collection.InsertOne(doc1); - collection.InsertOne(doc2); - collection.InsertOne(doc3); - } - catch (Exception ex) - { - throw new Exception(ex.Message); - } - } - private static void UpdateTestData() - { - var collection = GetMongoCollection(_connection.ConnectionString, _connection.Database, _connection.CollectionName); - - var filter1 = "{'bar':'foo'}"; - var filter2 = "{'qwe':'rty'}"; - var filter3 = "{'asd':'fgh'}"; - collection.DeleteMany(filter1); - collection.DeleteMany(filter2); - collection.DeleteMany(filter3); - } - - private static IMongoCollection GetMongoCollection(string connectionString, string database, string collectionName) - { - var dataBase = GetMongoDatabase(connectionString, database); - var collection = dataBase.GetCollection(collectionName); - return collection; - } - - private static IMongoDatabase GetMongoDatabase(string connectionString, string database) - { - var mongoClient = new MongoClient(connectionString); - var dataBase = mongoClient.GetDatabase(database); - return dataBase; - } - - private static bool GetDocuments(string updated) - { - var collection = GetMongoCollection(_connection.ConnectionString, _connection.Database, _connection.CollectionName); - var documents = collection.Find(new BsonDocument()).ToList(); - var i = documents.Any(x => x.Values.Contains(updated)); - return i; - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Frends.MongoDB.Update.Definitions; +using MongoDB.Bson; +using MongoDB.Driver; + +namespace Frends.MongoDB.Update.Tests; + +[TestClass] +public class UnitTests +{ + /* + Run command 'docker-compose up -d' in \Frends.MongoDB.Update.Tests\Files\ + */ + + private static readonly Connection _connection = new() + { + ConnectionString = "mongodb://admin:Salakala@localhost:27017/?authSource=admin", + Database = "testdb", + CollectionName = "testcoll", + }; + + private readonly string _doc1 = "{ 'foo':'bar', 'bar': 'foo' }"; + private readonly string _doc2 = "{ 'foo':'bar', 'bar': 'foo' }"; + private readonly string _doc3 = "{ 'qwe':'rty', 'asd': 'fgh' }"; + + + [TestInitialize] + public void StartUp() + { + InsertTestData(); + } + + [TestCleanup] + public void CleanUp() + { + UpdateTestData(); + } + + [TestMethod] + public async Task Test_Update_NotFound() + { + var _input = new Input() + { + InputType = InputType.Filter, + UpdateOptions = Definitions.UpdateOptions.UpdateOne, + Filter = "{'not':'found'}", + Filters = null, + File = null, + UpdateString = "{$set: {foo:'update'}}" + }; + + var result = await MongoDB.Update(_input, _connection, default); + Assert.IsTrue(result.Success); + Assert.AreEqual(0, result.Count); + Assert.IsFalse(GetDocuments("update")); + } + + [TestMethod] + public async Task Test_Update_Single_UpdateOne() + { + var _input = new Input() + { + InputType = InputType.Filter, + UpdateOptions = Definitions.UpdateOptions.UpdateOne, + Filter = "{'foo':'bar'}", + Filters = null, + File = null, + UpdateString = "{$set: {foo:'update'}}" + }; + + var result = await MongoDB.Update(_input, _connection, default); + Assert.IsTrue(result.Success); + Assert.AreEqual(1, result.Count); + Assert.IsTrue(GetDocuments("update")); + } + + [TestMethod] + public async Task Test_Update_Single_UpdateMany() + { + var _input = new Input() + { + InputType = InputType.Filter, + UpdateOptions = Definitions.UpdateOptions.UpdateMany, + Filter = "{'foo':'bar'}", + Filters = null, + File = null, + UpdateString = "{$set: {foo:'update'}}" + }; + + var result = await MongoDB.Update(_input, _connection, default); + Assert.IsTrue(result.Success); + Assert.AreEqual(2, result.Count); + Assert.IsTrue(GetDocuments("update")); + } + + [TestMethod] + public async Task Test_Update_Array_UpdateOne() + { + var doc1 = new DocumentValues() { Value = "{'foo':'bar'}" }; + var doc2 = new DocumentValues() { Value = "{'qwe':'rty'}" }; + + var _input = new Input() + { + InputType = InputType.Filters, + UpdateOptions = Definitions.UpdateOptions.UpdateOne, + Filter = null, + Filters = new[] { doc1, doc2 }, + File = null, + UpdateString = "{$set: {foo:'update'}}" + }; + + var result = await MongoDB.Update(_input, _connection, default); + Assert.IsTrue(result.Success); + Assert.AreEqual(2, result.Count); + Assert.IsTrue(GetDocuments("update")); + } + + [TestMethod] + public async Task Test_Update_Array_UpdateMany() + { + var doc1 = new DocumentValues() { Value = "{'foo':'bar'}" }; + var doc2 = new DocumentValues() { Value = "{'qwe':'rty'}" }; + + var _input = new Input() + { + InputType = InputType.Filters, + UpdateOptions = Definitions.UpdateOptions.UpdateMany, + Filter = null, + Filters = new[] { doc1, doc2 }, + File = null, + UpdateString = "{$set: {foo:'update'}}" + }; + + var result = await MongoDB.Update(_input, _connection, default); + Assert.IsTrue(result.Success); + Assert.AreEqual(3, result.Count); + Assert.IsTrue(GetDocuments("update")); + } + + [TestMethod] + public async Task Test_Update_File_UpdateOne() + { + var _input = new Input() + { + InputType = InputType.File, + UpdateOptions = Definitions.UpdateOptions.UpdateOne, + Filter = null, + Filters = null, + File = "..//..//..//Files//testdata.json", + UpdateString = "{$set: {foo:'update'}}" + }; + + var result = await MongoDB.Update(_input, _connection, default); + Assert.IsTrue(result.Success); + Assert.AreEqual(1, result.Count); + Assert.IsTrue(GetDocuments("update")); + } + + [TestMethod] + public async Task Test_Update_File_UpdateMany() + { + var _input = new Input() + { + InputType = InputType.File, + UpdateOptions = Definitions.UpdateOptions.UpdateMany, + Filter = null, + Filters = null, + File = "..//..//..//Files//testdata.json", + UpdateString = "{$set: {foo:'update'}}" + }; + + var result = await MongoDB.Update(_input, _connection, default); + Assert.IsTrue(result.Success); + Assert.AreEqual(2, result.Count); + Assert.IsTrue(GetDocuments("update")); + } + + [TestMethod] + public void Test_InvalidConnectionString() + { + var _input = new Input() + { + InputType = InputType.File, + UpdateOptions = Definitions.UpdateOptions.UpdateMany, + Filter = null, + Filters = null, + File = "..//..//..//Files//testdata.json", + UpdateString = "{$set: {foo:'update'}}" + }; + + var connection = new Connection + { + ConnectionString = "mongodb://admin:Incorrect@localhost:27017/?authSource=invalid", + CollectionName = _connection.CollectionName, + Database = _connection.Database, + }; + + var ex = Assert.ThrowsExceptionAsync(async () => await MongoDB.Update(_input, connection, default)); + Assert.IsTrue(ex.Result.Message.StartsWith("Update error: System.Exception: UpdateOperation error: MongoDB.Driver.MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1.")); + } + + private void InsertTestData() + { + try + { + var collection = GetMongoCollection(_connection.ConnectionString, _connection.Database, _connection.CollectionName); + + var doc1 = BsonDocument.Parse(_doc1); + var doc2 = BsonDocument.Parse(_doc2); + var doc3 = BsonDocument.Parse(_doc3); + + collection.InsertOne(doc1); + collection.InsertOne(doc2); + collection.InsertOne(doc3); + } + catch (Exception ex) + { + throw new Exception(ex.Message); + } + } + private static void UpdateTestData() + { + var collection = GetMongoCollection(_connection.ConnectionString, _connection.Database, _connection.CollectionName); + + var filter1 = "{'bar':'foo'}"; + var filter2 = "{'qwe':'rty'}"; + var filter3 = "{'asd':'fgh'}"; + collection.DeleteMany(filter1); + collection.DeleteMany(filter2); + collection.DeleteMany(filter3); + } + + private static IMongoCollection GetMongoCollection(string connectionString, string database, string collectionName) + { + var dataBase = GetMongoDatabase(connectionString, database); + var collection = dataBase.GetCollection(collectionName); + return collection; + } + + private static IMongoDatabase GetMongoDatabase(string connectionString, string database) + { + var mongoClient = new MongoClient(connectionString); + var dataBase = mongoClient.GetDatabase(database); + return dataBase; + } + + private static bool GetDocuments(string updated) + { + var collection = GetMongoCollection(_connection.ConnectionString, _connection.Database, _connection.CollectionName); + var documents = collection.Find(new BsonDocument()).ToList(); + var i = documents.Any(x => x.Values.Contains(updated)); + return i; + } } \ No newline at end of file diff --git a/Frends.MongoDB.Update/Frends.MongoDB.Update/Frends.MongoDB.Update.csproj b/Frends.MongoDB.Update/Frends.MongoDB.Update/Frends.MongoDB.Update.csproj index 1258525..1d16c54 100644 --- a/Frends.MongoDB.Update/Frends.MongoDB.Update/Frends.MongoDB.Update.csproj +++ b/Frends.MongoDB.Update/Frends.MongoDB.Update/Frends.MongoDB.Update.csproj @@ -2,7 +2,7 @@ net6.0 - 1.0.0 + 1.0.1 Frends Frends Frends @@ -14,15 +14,38 @@ https://frends.com/ https://github.com/FrendsPlatform/Frends.MongoDB - - - - PreserveNewest - - - - - - - + + + + PreserveNewest + + + true + + + true + + + + + + + + + + + + + + + + + + + lib\MongoDB.Driver.dll + + + lib\MongoDB.Driver.Core.dll + + \ No newline at end of file diff --git a/Frends.MongoDB.Update/Frends.MongoDB.Update/lib/MongoDB.Driver.Core.dll b/Frends.MongoDB.Update/Frends.MongoDB.Update/lib/MongoDB.Driver.Core.dll new file mode 100644 index 0000000..ef4f87f Binary files /dev/null and b/Frends.MongoDB.Update/Frends.MongoDB.Update/lib/MongoDB.Driver.Core.dll differ diff --git a/Frends.MongoDB.Update/Frends.MongoDB.Update/lib/MongoDB.Driver.dll b/Frends.MongoDB.Update/Frends.MongoDB.Update/lib/MongoDB.Driver.dll new file mode 100644 index 0000000..a5f429a Binary files /dev/null and b/Frends.MongoDB.Update/Frends.MongoDB.Update/lib/MongoDB.Driver.dll differ