Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDB.Query - Fixed dll issue #20

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Frends.MongoDB.Query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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-10-28
### Added
- Initial implementation
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.22.0" />
<PackageReference Include="MongoDB.Driver.Core" Version="2.22.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Frends.MongoDB.Query\Frends.MongoDB.Query.csproj" />
</ItemGroup>
Expand Down
272 changes: 149 additions & 123 deletions Frends.MongoDB.Query/Frends.MongoDB.Query.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,124 +1,150 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Frends.MongoDB.Query.Definitions;
using MongoDB.Bson;
using MongoDB.Driver;

namespace Frends.MongoDB.Query.Tests;

[TestClass]
public class UnitTests
{
/*
Run command 'docker-compose up -d' in \Frends.MongoDB.Query.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()
{
DeleteTestData();
}

[TestMethod]
public void Test_Query_TwoResults()
{
var _input = new Input()
{
Filter = "{'foo':'bar'}"
};

var result = MongoDB.Query(_input, _connection, default);
Assert.IsTrue(result.Success.Equals(true));
Assert.IsTrue(result.Data.Count == 2);
}

[TestMethod]
public void Test_Query_OneResults()
{
var _input = new Input()
{
Filter = "{'qwe':'rty'}"
};

var result = MongoDB.Query(_input, _connection, default);
Assert.IsTrue(result.Success.Equals(true));
Assert.IsTrue(result.Data.Count == 1);
}

[TestMethod]
public void Test_Query_NotFoundFilter()
{
var _input = new Input()
{
Filter = "{'not':'found'}",
};

var result = MongoDB.Query(_input, _connection, default);
Assert.IsTrue(result.Success.Equals(true));
Assert.IsTrue(result.Data.Count == 0);
}

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 IMongoCollection<BsonDocument> GetMongoCollection(string connectionString, string database, string collectionName)
{
var dataBase = GetMongoDatabase(connectionString, database);
var collection = dataBase.GetCollection<BsonDocument>(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 void DeleteTestData()
{
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);
}
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Frends.MongoDB.Query.Definitions;
using MongoDB.Bson;
using MongoDB.Driver;

namespace Frends.MongoDB.Query.Tests;

[TestClass]
public class UnitTests
{
/*
Run command 'docker-compose up -d' in \Frends.MongoDB.Query.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()
{
DeleteTestData();
}

[TestMethod]
public void Test_Query_TwoResults()
{
var _input = new Input()
{
Filter = "{'foo':'bar'}"
};

var result = MongoDB.Query(_input, _connection, default);
Assert.IsTrue(result.Success);
Assert.AreEqual(2, result.Data.Count);
}

[TestMethod]
public void Test_Query_OneResults()
{
var _input = new Input()
{
Filter = "{'qwe':'rty'}"
};

var result = MongoDB.Query(_input, _connection, default);
Assert.IsTrue(result.Success);
Assert.AreEqual(1, result.Data.Count);
}

[TestMethod]
public void Test_Query_NotFoundFilter()
{
var _input = new Input()
{
Filter = "{'not':'found'}",
};

var result = MongoDB.Query(_input, _connection, default);
Assert.IsTrue(result.Success);
Assert.AreEqual(0, result.Data.Count);
}

[TestMethod]
public void Test_EmptyQuery()
{
var ex = Assert.ThrowsException<Exception>(() => MongoDB.Query(new Input { Filter = "" }, _connection, default));
Assert.AreEqual("Query error: Filter can't be null.", ex.Message);
}

[TestMethod]
public void Test_InvalidConnectionString()
{
var input = new Input()
{
Filter = "{'not':'found'}",
};

var connection = new Connection
{
ConnectionString = "mongodb://admin:Incorrect@localhost:27017/?authSource=invalid",
CollectionName = _connection.CollectionName,
Database = _connection.Database,
};

var ex = Assert.ThrowsException<Exception>(() => MongoDB.Query(input, connection, default));
Assert.IsTrue(ex.Message.StartsWith("Query 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 IMongoCollection<BsonDocument> GetMongoCollection(string connectionString, string database, string collectionName)
{
var dataBase = GetMongoDatabase(connectionString, database);
var collection = dataBase.GetCollection<BsonDocument>(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 void DeleteTestData()
{
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<Version>1.0.0</Version>
<Version>1.0.1</Version>
<Authors>Frends</Authors>
<Copyright>Frends</Copyright>
<Company>Frends</Company>
Expand All @@ -14,15 +14,38 @@
<PackageProjectUrl>https://frends.com/</PackageProjectUrl>
<RepositoryUrl>https://github.com/FrendsPlatform/Frends.MongoDB</RepositoryUrl>
</PropertyGroup>

<ItemGroup>
<None Include="FrendsTaskMetadata.json" Pack="true" PackagePath="/">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Bson" Version="2.18.0" />
<PackageReference Include="MongoDB.Driver" Version="2.18.0" />
</ItemGroup>

<ItemGroup>
<None Include="FrendsTaskMetadata.json" Pack="true" PackagePath="/">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="lib\MongoDB.Driver.dll" Pack="true" PackagePath="/lib/$(TargetFrameworks)">
<CopyToOutputDirectory>true</CopyToOutputDirectory>
</None>
<None Include="lib\MongoDB.Driver.Core.dll" Pack="true" PackagePath="/lib/$(TargetFrameworks)">
<CopyToOutputDirectory>true</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Bson" Version="2.22.0" />
<PackageReference Include="MongoDB.Libmongocrypt" Version="1.8.0" PrivateAssets="true" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="SharpCompress" Version="0.34.2" />
<PackageReference Include="Snappier" Version="1.1.2" />
<PackageReference Include="System.Buffers" Version="4.5.1" />
<PackageReference Include="ZstdSharp.Port" Version="0.7.3" />
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.300.7" />
<PackageReference Include="DnsClient" Version="1.7.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<Reference Include="MongoDB.Driver" Version="2.22.0">
<HintPath>lib\MongoDB.Driver.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver.Core" Version="2.22.0">
<HintPath>lib\MongoDB.Driver.Core.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
Binary file not shown.
Binary file not shown.
Loading