From e86fe2e8cf34343cf3ebbf4640b2be5e85899615 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 6 Aug 2019 10:41:16 +0300 Subject: v2 Basic structure. --- Software/Visual_Studio_v2/Tango.BLL/ObjectBase.cs | 11 +++ .../Tango.BLL/Objects/Organization.cs | 12 +++ Software/Visual_Studio_v2/Tango.BLL/ServiceBase.cs | 14 +++ .../Tango.BLL/Services/OrganizationsService.cs | 39 +++++++++ .../Visual_Studio_v2/Tango.BLL/Tango.BLL.csproj | 11 +++ .../Tango.DAL.Mongo/MongoDataBaseSettings.cs | 12 +++ .../Tango.DAL.Mongo/MongoRepository.cs | 76 +++++++++++++++++ .../Tango.DAL.Mongo/Tango.DAL.Mongo.csproj | 15 ++++ .../Attributes/MongoCollectionAttribute.cs | 17 ++++ .../Tango.DAL/Entities/OrganizationEntity.cs | 11 +++ Software/Visual_Studio_v2/Tango.DAL/Entity.cs | 15 ++++ Software/Visual_Studio_v2/Tango.DAL/IRepository.cs | 24 ++++++ .../Visual_Studio_v2/Tango.DAL/Tango.DAL.csproj | 11 +++ .../Visual_Studio_v2/Tango.UnitTests/DAL/Mongo.cs | 45 ++++++++++ .../Tango.UnitTests/Properties/AssemblyInfo.cs | 20 +++++ .../Tango.UnitTests/Tango.UnitTests.csproj | 99 ++++++++++++++++++++++ .../Visual_Studio_v2/Tango.UnitTests/app.config | 11 +++ .../Tango.UnitTests/packages.config | 11 +++ Software/Visual_Studio_v2/Tango.sln | 43 ++++++++++ 19 files changed, 497 insertions(+) create mode 100644 Software/Visual_Studio_v2/Tango.BLL/ObjectBase.cs create mode 100644 Software/Visual_Studio_v2/Tango.BLL/Objects/Organization.cs create mode 100644 Software/Visual_Studio_v2/Tango.BLL/ServiceBase.cs create mode 100644 Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs create mode 100644 Software/Visual_Studio_v2/Tango.BLL/Tango.BLL.csproj create mode 100644 Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoDataBaseSettings.cs create mode 100644 Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoRepository.cs create mode 100644 Software/Visual_Studio_v2/Tango.DAL.Mongo/Tango.DAL.Mongo.csproj create mode 100644 Software/Visual_Studio_v2/Tango.DAL/Attributes/MongoCollectionAttribute.cs create mode 100644 Software/Visual_Studio_v2/Tango.DAL/Entities/OrganizationEntity.cs create mode 100644 Software/Visual_Studio_v2/Tango.DAL/Entity.cs create mode 100644 Software/Visual_Studio_v2/Tango.DAL/IRepository.cs create mode 100644 Software/Visual_Studio_v2/Tango.DAL/Tango.DAL.csproj create mode 100644 Software/Visual_Studio_v2/Tango.UnitTests/DAL/Mongo.cs create mode 100644 Software/Visual_Studio_v2/Tango.UnitTests/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio_v2/Tango.UnitTests/Tango.UnitTests.csproj create mode 100644 Software/Visual_Studio_v2/Tango.UnitTests/app.config create mode 100644 Software/Visual_Studio_v2/Tango.UnitTests/packages.config create mode 100644 Software/Visual_Studio_v2/Tango.sln diff --git a/Software/Visual_Studio_v2/Tango.BLL/ObjectBase.cs b/Software/Visual_Studio_v2/Tango.BLL/ObjectBase.cs new file mode 100644 index 000000000..be78b4bc0 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.BLL/ObjectBase.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tango.BLL +{ + public abstract class ObjectBase + { + + } +} diff --git a/Software/Visual_Studio_v2/Tango.BLL/Objects/Organization.cs b/Software/Visual_Studio_v2/Tango.BLL/Objects/Organization.cs new file mode 100644 index 000000000..3750fb909 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.BLL/Objects/Organization.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tango.BLL.Objects +{ + public class Organization : ObjectBase + { + public string ID { get; set; } + public string Name { get; set; } + } +} diff --git a/Software/Visual_Studio_v2/Tango.BLL/ServiceBase.cs b/Software/Visual_Studio_v2/Tango.BLL/ServiceBase.cs new file mode 100644 index 000000000..211d1046c --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.BLL/ServiceBase.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tango.BLL +{ + public abstract class ServiceBase : IDisposable where T : ObjectBase + { + public virtual void Dispose() + { + //Do nothing. + } + } +} diff --git a/Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs b/Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs new file mode 100644 index 000000000..a65952846 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.BLL/Services/OrganizationsService.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Tango.BLL.Objects; +using Tango.DAL; +using Tango.DAL.Entities; +using System.Linq; + +namespace Tango.BLL.Services +{ + public class OrganizationsService : ServiceBase + { + private IRepository _repository; + + public OrganizationsService(IRepository repository) + { + _repository = repository; + } + + public async Task> GetAll() + { + var entities = await _repository.GetAllAsync(); + + List organizations = new List(); + + foreach (var entity in entities) + { + Organization organization = new Organization(); + organization.ID = entity.ID; + organization.Name = entity.Name; + + organizations.Add(organization); + } + + return organizations; + } + } +} diff --git a/Software/Visual_Studio_v2/Tango.BLL/Tango.BLL.csproj b/Software/Visual_Studio_v2/Tango.BLL/Tango.BLL.csproj new file mode 100644 index 000000000..bc3617fb9 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.BLL/Tango.BLL.csproj @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git a/Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoDataBaseSettings.cs b/Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoDataBaseSettings.cs new file mode 100644 index 000000000..5c44f2022 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoDataBaseSettings.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tango.DAL.Mongo +{ + public class MongoDataBaseSettings + { + public String Address { get; set; } + public String DatabaseName { get; set; } + } +} diff --git a/Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoRepository.cs b/Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoRepository.cs new file mode 100644 index 000000000..d268f434d --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.DAL.Mongo/MongoRepository.cs @@ -0,0 +1,76 @@ +using MongoDB.Driver; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using System.Reflection; +using Tango.DAL.Attributes; +using System.Linq.Expressions; +using MongoDB.Driver.Linq; + +namespace Tango.DAL.Mongo +{ + public class MongoRepository : IRepository where T : Entity + { + private IMongoDatabase _database; + private MongoClient _client; + private IMongoCollection _collection; + + public MongoRepository(MongoDataBaseSettings settings) + { + _client = new MongoClient(settings.Address); + _database = _client.GetDatabase(settings.DatabaseName); + } + + private IMongoCollection GetCollection() + { + if (_collection == null) + { + _collection = _database.GetCollection(typeof(T).GetCustomAttribute().Name); + } + + return _collection; + } + + public async Task> GetAllAsync() + { + return await (await GetCollection().FindAsync(x => true)).ToListAsync(); + } + + public async Task> GetAsync(Expression> filter) + { + return await (await GetCollection().FindAsync(filter)).ToListAsync(); + } + + public async Task ReplaceAsync(T entity) + { + await GetCollection().ReplaceOneAsync(x => x.ID == entity.ID, entity); + return entity; + } + + public async Task DeleteAsync(Expression> filter) + { + return (await GetCollection().DeleteOneAsync(filter)).DeletedCount; + } + + public async Task Insert(T entity) + { + await GetCollection().InsertOneAsync(entity); + return entity; + } + + public Task Count() + { + return GetCollection().CountDocumentsAsync(x => true); + } + + public Task Count(Expression> filter) + { + return GetCollection().CountDocumentsAsync(filter); + } + + public void Dispose() + { + + } + } +} diff --git a/Software/Visual_Studio_v2/Tango.DAL.Mongo/Tango.DAL.Mongo.csproj b/Software/Visual_Studio_v2/Tango.DAL.Mongo/Tango.DAL.Mongo.csproj new file mode 100644 index 000000000..7f0e7a2f0 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.DAL.Mongo/Tango.DAL.Mongo.csproj @@ -0,0 +1,15 @@ + + + + netstandard2.0 + + + + + + + + + + + diff --git a/Software/Visual_Studio_v2/Tango.DAL/Attributes/MongoCollectionAttribute.cs b/Software/Visual_Studio_v2/Tango.DAL/Attributes/MongoCollectionAttribute.cs new file mode 100644 index 000000000..50b585698 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.DAL/Attributes/MongoCollectionAttribute.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tango.DAL.Attributes +{ + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] + public class MongoCollectionAttribute : Attribute + { + public String Name { get; set; } + + public MongoCollectionAttribute(String name) + { + Name = name; + } + } +} diff --git a/Software/Visual_Studio_v2/Tango.DAL/Entities/OrganizationEntity.cs b/Software/Visual_Studio_v2/Tango.DAL/Entities/OrganizationEntity.cs new file mode 100644 index 000000000..b17cd34c9 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.DAL/Entities/OrganizationEntity.cs @@ -0,0 +1,11 @@ +using System; +using Tango.DAL.Attributes; + +namespace Tango.DAL.Entities +{ + [MongoCollection("Organizations")] + public class OrganizationEntity : Entity + { + public string Name { get; set; } + } +} diff --git a/Software/Visual_Studio_v2/Tango.DAL/Entity.cs b/Software/Visual_Studio_v2/Tango.DAL/Entity.cs new file mode 100644 index 000000000..d299dcc78 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.DAL/Entity.cs @@ -0,0 +1,15 @@ +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tango.DAL +{ + public abstract class Entity + { + [BsonId] + [BsonRepresentation(BsonType.ObjectId)] + public string ID { get; set; } + } +} diff --git a/Software/Visual_Studio_v2/Tango.DAL/IRepository.cs b/Software/Visual_Studio_v2/Tango.DAL/IRepository.cs new file mode 100644 index 000000000..a6d6989dd --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.DAL/IRepository.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.DAL +{ + public interface IRepository : IDisposable + { + + } + + public interface IRepository : IRepository where T : Entity + { + Task> GetAsync(Expression> filter); + Task> GetAllAsync(); + Task ReplaceAsync(T entity); + Task DeleteAsync(Expression> filter); + Task Insert(T entity); + Task Count(); + Task Count(Expression> filter); + } +} diff --git a/Software/Visual_Studio_v2/Tango.DAL/Tango.DAL.csproj b/Software/Visual_Studio_v2/Tango.DAL/Tango.DAL.csproj new file mode 100644 index 000000000..6fa539f1e --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.DAL/Tango.DAL.csproj @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git a/Software/Visual_Studio_v2/Tango.UnitTests/DAL/Mongo.cs b/Software/Visual_Studio_v2/Tango.UnitTests/DAL/Mongo.cs new file mode 100644 index 000000000..8a2314858 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.UnitTests/DAL/Mongo.cs @@ -0,0 +1,45 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Tango.DAL.Entities; +using Tango.DAL.Mongo; +using System.Linq; + +namespace Tango.UnitTests.DAL +{ + [TestClass] + public class Mongo + { + [TestMethod] + public void Simple_Operations() + { + MongoRepository repo = new MongoRepository(new MongoDataBaseSettings() + { + Address = "mongodb://localhost:27017", + DatabaseName = "TEST" + }); + + repo.DeleteAsync(x => true).GetAwaiter().GetResult(); + + OrganizationEntity org1 = new OrganizationEntity(); + org1.Name = "Org 1"; + + repo.Insert(org1).GetAwaiter().GetResult(); + + Assert.IsNotNull(org1.ID); + + var org2 = repo.GetAsync(x => x.ID == org1.ID).GetAwaiter().GetResult().FirstOrDefault(); + + Assert.IsNotNull(org2); + + Assert.AreEqual(org1.Name, org2.Name); + + long count = repo.DeleteAsync(x => x.ID == org1.ID).GetAwaiter().GetResult(); + + Assert.AreEqual(count, 1); + + count = repo.Count().GetAwaiter().GetResult(); + + Assert.AreEqual(count, 0); + } + } +} diff --git a/Software/Visual_Studio_v2/Tango.UnitTests/Properties/AssemblyInfo.cs b/Software/Visual_Studio_v2/Tango.UnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..374da8010 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.UnitTests/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Tango.UnitTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tango.UnitTests")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("932d6bf7-ed35-4ffa-a573-356c071ca727")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Software/Visual_Studio_v2/Tango.UnitTests/Tango.UnitTests.csproj b/Software/Visual_Studio_v2/Tango.UnitTests/Tango.UnitTests.csproj new file mode 100644 index 000000000..bcdb3c11f --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.UnitTests/Tango.UnitTests.csproj @@ -0,0 +1,99 @@ + + + + + + Debug + AnyCPU + {932D6BF7-ED35-4FFA-A573-356C071CA727} + Library + Properties + Tango.UnitTests + Tango.UnitTests + v4.6.1 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\DnsClient.1.2.0\lib\net45\DnsClient.dll + + + ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + ..\packages\MongoDB.Bson.2.8.1\lib\net452\MongoDB.Bson.dll + + + ..\packages\MongoDB.Driver.2.8.1\lib\net452\MongoDB.Driver.dll + + + ..\packages\MongoDB.Driver.Core.2.8.1\lib\net452\MongoDB.Driver.Core.dll + + + + ..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + True + + + + + + + + + + + + + {9d1f1789-745c-4725-9dc4-12e0b0090a64} + Tango.DAL.Mongo + + + {9701ad8c-5b58-4a1e-be59-ef4de36549d9} + Tango.DAL + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio_v2/Tango.UnitTests/app.config b/Software/Visual_Studio_v2/Tango.UnitTests/app.config new file mode 100644 index 000000000..d592063f0 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.UnitTests/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio_v2/Tango.UnitTests/packages.config b/Software/Visual_Studio_v2/Tango.UnitTests/packages.config new file mode 100644 index 000000000..9852f98c8 --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.UnitTests/packages.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio_v2/Tango.sln b/Software/Visual_Studio_v2/Tango.sln new file mode 100644 index 000000000..abe68497f --- /dev/null +++ b/Software/Visual_Studio_v2/Tango.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28010.2048 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.DAL", "Tango.DAL\Tango.DAL.csproj", "{9701AD8C-5B58-4A1E-BE59-EF4DE36549D9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.BLL", "Tango.BLL\Tango.BLL.csproj", "{5F1F3818-A7E7-4810-95DE-F5C1442B21C1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.DAL.Mongo", "Tango.DAL.Mongo\Tango.DAL.Mongo.csproj", "{9D1F1789-745C-4725-9DC4-12E0B0090A64}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.UnitTests", "Tango.UnitTests\Tango.UnitTests.csproj", "{932D6BF7-ED35-4FFA-A573-356C071CA727}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9701AD8C-5B58-4A1E-BE59-EF4DE36549D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9701AD8C-5B58-4A1E-BE59-EF4DE36549D9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9701AD8C-5B58-4A1E-BE59-EF4DE36549D9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9701AD8C-5B58-4A1E-BE59-EF4DE36549D9}.Release|Any CPU.Build.0 = Release|Any CPU + {5F1F3818-A7E7-4810-95DE-F5C1442B21C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5F1F3818-A7E7-4810-95DE-F5C1442B21C1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F1F3818-A7E7-4810-95DE-F5C1442B21C1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5F1F3818-A7E7-4810-95DE-F5C1442B21C1}.Release|Any CPU.Build.0 = Release|Any CPU + {9D1F1789-745C-4725-9DC4-12E0B0090A64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9D1F1789-745C-4725-9DC4-12E0B0090A64}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9D1F1789-745C-4725-9DC4-12E0B0090A64}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9D1F1789-745C-4725-9DC4-12E0B0090A64}.Release|Any CPU.Build.0 = Release|Any CPU + {932D6BF7-ED35-4FFA-A573-356C071CA727}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {932D6BF7-ED35-4FFA-A573-356C071CA727}.Debug|Any CPU.Build.0 = Debug|Any CPU + {932D6BF7-ED35-4FFA-A573-356C071CA727}.Release|Any CPU.ActiveCfg = Release|Any CPU + {932D6BF7-ED35-4FFA-A573-356C071CA727}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {64685705-FA96-4958-9637-791C0DCBC200} + EndGlobalSection +EndGlobal -- cgit v1.3.1