コード例 #1
0
        private bool AreEqual(AssetConditionLayerModel a, IAssetConditionLayer b)
        {
            if (a == null && b == null)
            {
                return(true);
            }

            if (a != null && b == null || a == null)
            {
                return(false);
            }

            if (a.Id != b.Id ||
                a.Description != b.Description ||
                a.Priority != b.Priority ||
                a.ClientsCanCashInViaBankCards != b.ClientsCanCashInViaBankCards ||
                a.SwiftDepositEnabled != b.SwiftDepositEnabled)
            {
                return(false);
            }

            if ((a.AssetConditions?.Count ?? 0) != (b.AssetConditions?.Count ?? 0))
            {
                return(false);
            }

            return(a.AssetConditions == null ||
                   a.AssetConditions.Count == 0 ||
                   a.AssetConditions.All(o => b.AssetConditions.Any(p => AreEqual(o, p))));
        }
コード例 #2
0
        public async Task GetLayerAsync_Return_Layer_With_Conditions()
        {
            // arrange
            var layer = new AssetConditionLayerDto
            {
                Id = "layer_1"
            };

            var conditions = new List <IAssetCondition>
            {
                new AssetCondition("asset_1"),
                new AssetCondition("asset_2")
            };

            var defaultConditions = new AssetDefaultCondition();

            _assetConditionLayerRepositoryMock.Setup(o => o.GetAsync(It.Is <string>(p => p == layer.Id)))
            .Returns(Task.FromResult((IAssetConditionLayer)layer));

            _assetConditionCacheMock.Setup(o => o.GetListAsync(It.Is <string>(p => p == layer.Id), It.IsAny <Func <Task <IEnumerable <IAssetCondition> > > >()))
            .Returns(Task.FromResult(Mapper.Map <IEnumerable <AssetConditionDto> >(conditions)));

            _assetDefaultConditionRepositoryMock.Setup(o => o.GetAsync(It.Is <string>(p => p == layer.Id)))
            .Returns(Task.FromResult((IAssetDefaultCondition)defaultConditions));

            // act
            IAssetConditionLayer result = await _service.GetLayerAsync(layer.Id);

            // assert
            Assert.IsTrue(result?.AssetConditions.Count == conditions.Count && result.AssetDefaultCondition != null);
        }
コード例 #3
0
        public async Task UpdateLayerAsync(IAssetConditionLayer layer)
        {
            await _myNoSqlWriter.Clear();

            await _assetConditionLayerRepository.InsertOrReplaceAsync(layer);

            await _cacheManager.ClearCacheAsync("Updated condition layer");
        }
コード例 #4
0
        /// <summary>
        /// Adds or entirely replaces an asset conditions layer.
        /// </summary>
        /// <param name="layer">The asset conditon layer.</param>
        /// <returns></returns>
        public async Task InsertOrReplaceAsync(IAssetConditionLayer layer)
        {
            var entity = new AssetConditionLayerEntity(GetPartitionKey(), GetRowKey(layer.Id));

            Mapper.Map(layer, entity);

            await _storage.InsertOrReplaceAsync(entity);
        }
コード例 #5
0
        public async Task GetClientLayers_Return_Layers_With_Conditions()
        {
            // arrange
            string clientId = "client_1";

            var layer = new AssetConditionLayerDto
            {
                Id = "layer_1"
            };

            var conditions = new List <IAssetCondition>
            {
                new AssetCondition("asset_1"),
                new AssetCondition("asset_2")
            };

            var defaultConditions = new AssetDefaultCondition();

            _assetConditionLayerLinkClientRepositoryMock.Setup(o => o.GetLayersAsync(It.Is <string>(p => p == clientId)))
            .Returns(Task.FromResult((IEnumerable <string>) new List <string>
            {
                layer.Id
            }));

            _assetConditionLayerRepositoryMock.Setup(o =>
                                                     o.GetAsync(It.Is <IEnumerable <string> >(p => p.First() == layer.Id)))
            .Returns(Task.FromResult((IEnumerable <IAssetConditionLayer>) new List <IAssetConditionLayer>
            {
                layer
            }));

            _assetConditionCacheMock.Setup(o => o.GetListAsync(It.Is <string>(p => p == layer.Id), It.IsAny <Func <Task <IEnumerable <IAssetCondition> > > >()))
            .Returns(Task.FromResult(Mapper.Map <IEnumerable <AssetConditionDto> >(conditions)));

            _assetDefaultConditionRepositoryMock.Setup(o => o.GetAsync(It.Is <string>(p => p == layer.Id)))
            .Returns(Task.FromResult((IAssetDefaultCondition)defaultConditions));

            // act
            IEnumerable <IAssetConditionLayer> result = await _service.GetClientLayers(clientId);

            // assert
            IAssetConditionLayer firstConditionLayer = result.First();

            Assert.IsTrue(firstConditionLayer.AssetConditions.Count == conditions.Count && firstConditionLayer.AssetDefaultCondition != null);
        }
コード例 #6
0
 public async Task AddLayerAsync(IAssetConditionLayer layer)
 {
     await _assetConditionLayerRepository.InsertOrReplaceAsync(layer);
 }