Beispiel #1
0
        public async Task <List <UserItemDto> > GetAllUserItem(UserQueryInput input)
        {
            var users = await _stateManager.GetOrAddAsync <IReliableDictionary <ItemId, UserItem> >(DictionaryName);

            List <UserItemDto> list = new List <UserItemDto>();

            using (var tx = _stateManager.CreateTransaction())
            {
                var enumerator       = (await users.CreateEnumerableAsync(tx)).GetAsyncEnumerator();
                CancellationToken ct = default(CancellationToken);
                while (await enumerator.MoveNextAsync(ct))
                {
                    var currentUser = enumerator.Current.Value;
                    if (input.CheckCriteria(currentUser))
                    {
                        list.Add(_mapper.Map <UserItemDto>(currentUser));
                    }
                }
            }
            return(list);
        }
        public void Test_CheckCreatedCriteria()
        {
            var inputs = new List <UserItem>();

            for (int i = 0; i < 12; i++)
            {
                var item = new UserItem(null, "test" + i, null, "TestUser" + i, null, null, null, null, null, null, null);
                item.SetCreated(new DateTimeOffset(2018, i + 1, 1, 1, 1, 1, TimeSpan.Zero));
                inputs.Add(item);
            }
            var result = new List <UserItem>();

            // StartCreated != null && EndCreated != null
            var query = new UserQueryInput
            {
                StartCreated = new DateTimeOffset(2018, 3, 1, 1, 1, 1, TimeSpan.Zero),
                EndCreated   = new DateTimeOffset(2018, 8, 1, 1, 1, 1, TimeSpan.Zero)
            };

            result = new List <UserItem>();
            foreach (var item in inputs)
            {
                if (query.CheckCriteria(item))
                {
                    result.Add(item);
                }
            }
            Assert.AreEqual(6, result.Count);

            // StartCreated = null
            query = new UserQueryInput
            {
                StartCreated = null,
                EndCreated   = new DateTimeOffset(2018, 8, 1, 1, 1, 1, TimeSpan.Zero)
            };
            result = new List <UserItem>();
            foreach (var item in inputs)
            {
                if (query.CheckCriteria(item))
                {
                    result.Add(item);
                }
            }
            Assert.AreEqual(8, result.Count);

            // EndCreated = null

            result = new List <UserItem>();
            query  = new UserQueryInput
            {
                StartCreated = new DateTimeOffset(2018, 8, 1, 1, 1, 1, TimeSpan.Zero),
                EndCreated   = null
            };
            foreach (var item in inputs)
            {
                if (query.CheckCriteria(item))
                {
                    result.Add(item);
                }
            }
            Assert.AreEqual(5, result.Count);

            // StartCreated = null and EndCreated = null
            query = new UserQueryInput
            {
                StartCreated = null,
                EndCreated   = null
            };
            result = new List <UserItem>();
            foreach (var item in inputs)
            {
                if (query.CheckCriteria(item))
                {
                    result.Add(item);
                }
            }
            Assert.AreEqual(12, result.Count);
        }