示例#1
0
        public void Initialize()
        {
            FulcrumApplicationHelper.UnitTestSetup(nameof(ManyToOneTest));
            var connectionString = TestSettings.ConnectionString;

            FulcrumAssert.IsNotNullOrWhiteSpace(connectionString);
            var manyTableMetadata = new SqlTableMetadata
            {
                TableName         = "TestItem",
                CustomColumnNames = new[] { "Value", "IncreasingNumber", "NumberModulo", "DecreasingString", "ParentId" },
                OrderBy           = new string[] { }
            };
            var oneTableMetadata = new SqlTableMetadata
            {
                TableName         = "TestItem",
                CustomColumnNames = new[] { "Value" },
                OrderBy           = new string[] { }
            };

            _oneStorage = new CrudSql <TestItemId <Guid> >(new DatabaseOptions
            {
                ConnectionString = connectionString
            }, oneTableMetadata);
            _manyStorage = new ManyToOneSql <TestItemManyToOneCreate <Guid, Guid?>, TestItemManyToOne <Guid, Guid?>, TestItemId <Guid> >(
                new DatabaseOptions
            {
                ConnectionString = connectionString
            }, manyTableMetadata, "ParentId", _oneStorage);
        }
示例#2
0
 public void Initialize()
 {
     FulcrumApplicationHelper.UnitTestSetup(typeof(TestAutoCacheManyToOneRecursive).FullName);
     _storage = new ManyToOneMemory <ItemWithParentId, Guid>(item => item.ParentId);
     Cache    = new MemoryDistributedCache();
     DistributedCacheOptions = new DistributedCacheEntryOptions
     {
         AbsoluteExpirationRelativeToNow = TimeSpan.FromMilliseconds(1000)
     };
     AutoCacheOptions = new AutoCacheOptions
     {
         AbsoluteExpirationRelativeToNow = DistributedCacheOptions.AbsoluteExpirationRelativeToNow
     };
     _autoCache = new ManyToOneAutoCache <ItemWithParentId, Guid>(_storage, Cache, null, AutoCacheOptions);
 }
示例#3
0
        public void Initialize()
        {
            FulcrumApplicationHelper.UnitTestSetup(typeof(CrudManyToOneRecursiveRestClientTest).FullName);
            HttpClientMock = new Mock <IHttpClient>();
            HttpSender.DefaultHttpClient = HttpClientMock.Object;
            var httpSender = new HttpSender(ResourcePath)
            {
                HttpClient = HttpClientMock.Object
            };

            _oneManyClient = new CrudManyToOneRestClient2 <Person, Guid>(httpSender, "Persons", "Many");
            _person        = new Person()
            {
                GivenName = "Kalle",
                Surname   = "Anka"
            };
        }
        public void Initialize()
        {
            FulcrumApplicationHelper.UnitTestSetup(typeof(CrudManyToOneRestClientTest).FullName);
            HttpClientMock = new Mock <IHttpClient>();
            Libraries.Web.RestClientHelper.HttpSender.DefaultHttpClient = HttpClientMock.Object;
            var httpSender = new HttpSender(ResourcePath)
            {
                HttpClient = HttpClientMock.Object
            };

            _client  = new CrudManyToOneRestClient2 <Address, Guid>(httpSender, "Persons", "Addresses");
            _address = new Address()
            {
                Street = "Paradisäppelvägen 111",
                City   = "Ankeborg"
            };
        }
示例#5
0
        public async Task ReadChildrenWithPagingTest(ICrudManyToOne <Person, Guid> restClient, string resourceName)
        {
            var parentId     = Guid.NewGuid();
            var expectedUri  = $"{ResourcePath}/Persons/{parentId}/{resourceName}?offset=0";
            var pageEnvelope = new PageEnvelope <Person>(0, PageInfo.DefaultLimit, null, new[] { _person });

            HttpClientMock.Setup(client => client.SendAsync(
                                     It.Is <HttpRequestMessage>(request => request.RequestUri.AbsoluteUri == expectedUri && request.Method == HttpMethod.Get),
                                     CancellationToken.None))
            .ReturnsAsync((HttpRequestMessage r, CancellationToken c) => CreateResponseMessage(r, pageEnvelope))
            .Verifiable();
            var readPage = await restClient.ReadChildrenWithPagingAsync(parentId, 0);

            Assert.IsNotNull(readPage?.Data);
            Assert.AreEqual(1, readPage.Data.Count());
            Assert.AreEqual(_person, readPage.Data.FirstOrDefault());
            HttpClientMock.Verify();
        }
示例#6
0
        public void Inititalize()
        {
            var connectionString  = ConfigurationManager.AppSettings["ConnectionString"];
            var manyTableMetadata = new SqlTableMetadata
            {
                TableName         = "TestItem",
                CustomColumnNames = new[] { "Value", "ParentId" },
                OrderBy           = new string[] { }
            };
            var oneTableMetadata = new SqlTableMetadata
            {
                TableName         = "TestItem",
                CustomColumnNames = new[] { "Value" },
                OrderBy           = new string[] { }
            };

            _oneStorage  = new CrudSql <TestItemId <Guid> >(connectionString, oneTableMetadata);
            _manyStorage = new ManyToOneSql <TestItemManyToOneCreate <Guid?>, TestItemManyToOne <Guid, Guid?>, TestItemId <Guid> >(connectionString, manyTableMetadata, "ParentId", _oneStorage);
        }
示例#7
0
        public async Task ReadChildrenTest(ICrudManyToOne <Person, Guid> restClient, string resourceName)
        {
            var parentId    = Guid.NewGuid();
            var expectedUri = $"{ResourcePath}/Persons/{parentId}/{resourceName}?limit={int.MaxValue}";

            HttpClientMock.Setup(client => client.SendAsync(
                                     It.Is <HttpRequestMessage>(request => request.RequestUri.AbsoluteUri == expectedUri && request.Method == HttpMethod.Get),
                                     CancellationToken.None))
            .ReturnsAsync((HttpRequestMessage r, CancellationToken c) => CreateResponseMessage(r, new[] { _person }))
            .Verifiable();
            var persons = await restClient.ReadChildrenAsync(parentId);

            Assert.IsNotNull(persons);
            var personArray = persons as Person[] ?? persons.ToArray();

            Assert.AreEqual(1, personArray.Length);
            Assert.AreEqual(_person, personArray.FirstOrDefault());
            HttpClientMock.Verify();
        }
示例#8
0
 /// <inheritdoc />
 public DependentToMasterWithUniqueIdConvenience(ICrudManyToOne <TModel, TId> uniqueIdTable) : base(uniqueIdTable)
 {
 }
 public void Initialize()
 {
     _oneStorage      = new CrudMemory <TestItemId <Guid>, Guid>();
     _crudManyStorage = new ManyToOneMemory <TestItemManyToOneCreate <Guid, Guid?>, TestItemManyToOne <Guid, Guid?>, Guid>(item => item.ParentId);
 }
示例#10
0
 /// <inheritdoc />
 public DependentToMasterWithUniqueIdMemory(ICrudManyToOne <TModel, TId> uniqueIdTable) : base(uniqueIdTable)
 {
 }
 public ManyToOneConvenience(ICrudable <TModel, TId> service) : base(service)
 {
     _service = new ManyToOnePassThrough <TModelCreate, TModel, TId>(service);
 }
 /// <summary>
 /// Constructor for TOneModel that does not implement <see cref="IUniquelyIdentifiable{TId}"/>, or when you want to specify your own GetKey() method.
 /// </summary>
 /// <param name="service"></param>
 /// <param name="cache"></param>
 /// <param name="getIdDelegate"></param>
 /// <param name="flushCacheDelegateAsync"></param>
 /// <param name="options"></param>
 public ManyToOneAutoCache(ICrudManyToOne <TManyModel, TId> service,
                           GetIdDelegate <TManyModel, TId> getIdDelegate, IDistributedCache cache,
                           FlushCacheDelegateAsync flushCacheDelegateAsync = null, AutoCacheOptions options = null)
     : base(service, getIdDelegate, cache, flushCacheDelegateAsync, options)
 {
 }
 /// <summary>
 /// Constructor for TOneModel that implements <see cref="IUniquelyIdentifiable{TId}"/>.
 /// </summary>
 /// <param name="service"></param>
 /// <param name="cache"></param>
 /// <param name="flushCacheDelegateAsync"></param>
 /// <param name="options"></param>
 public ManyToOneAutoCache(ICrudManyToOne <TManyModel, TId> service, IDistributedCache cache,
                           FlushCacheDelegateAsync flushCacheDelegateAsync = null, AutoCacheOptions options = null)
     : this(service, item => ((IUniquelyIdentifiable <TId>)item).Id, cache, flushCacheDelegateAsync, options)
 {
 }