public async Task PostShouldFailedIfForbidden()
        {
            var repo       = new Repository <User>(_fixture.InMemoryStorage, new ClosedRightExpressionsHelper <User>(), _fixture.IncludeApplicator);
            var users      = new UsersCollectionWithHardcodedGetById(repo, _fixture.PatcherProvider, _fixture.Instanciator);
            var controller = new UsersAppController(_fixture.InMemoryStorage, users);
            var query      = new Query <User> {
                Verb = Helpers.HttpVerbs.Post
            };
            var id        = Guid.NewGuid();
            var candidate = _parser.Parse <User, Guid>($@"{{ ""id"": ""{id}"" }}");

            await Assert.ThrowsAsync <ForbiddenException>(() => controller.CreateAsync(candidate, query));
        }
        public async Task PostShouldNotCallGetByIdOnTheCollection()
        {
            var users      = new UsersCollectionWithHardcodedGetById(_fixture.UsersRepo, _fixture.PatcherProvider, _fixture.Instanciator);
            var controller = new UsersAppController(_fixture.InMemoryStorage, users);
            var query      = new Query <User>();

            query.Options.ChecksRights = false;
            var id        = Guid.NewGuid();
            var candidate = _parser.Parse <User, Guid>($@"{{ ""id"": ""{id}"" }}");

            var user = await controller.CreateAsync(candidate, query);

            Assert.Equal(id, user.Id);
        }
        public async Task CreateAsyncCollectionShouldFailedIfForbidden()
        {
            var repo       = new Repository <User>(_fixture.InMemoryStorage, new ClosedRightExpressionsHelper <User>(), _fixture.IncludeApplicator);
            var users      = new UsersCollectionWithHardcodedGetById(repo, _fixture.PatcherProvider, _fixture.Instanciator);
            var controller = new UsersAppController(_fixture.InMemoryStorage, users);

            await Assert.ThrowsAsync <ForbiddenException>(() => controller.CreateAsync(new List <User> {
                new User {
                    Id = Guid.NewGuid()
                }, new User {
                    Id = Guid.NewGuid()
                }
            }));
        }
        public async Task PostShouldWorkIfForbiddenButExplicitelyAllowed()
        {
            var repo       = new Repository <User>(_fixture.InMemoryStorage, new ClosedRightExpressionsHelper <User>(), _fixture.IncludeApplicator);
            var users      = new UsersCollectionWithHardcodedGetById(repo, _fixture.PatcherProvider, _fixture.Instanciator);
            var controller = new UsersAppController(_fixture.InMemoryStorage, users);
            var query      = new Query <User> {
                Verb = Helpers.HttpVerbs.Post
            };

            query.Options.ChecksRights = false;
            var id        = Guid.NewGuid();
            var candidate = _parser.Parse <User, Guid>($@"{{ ""id"": ""{id}"" }}");

            var user = await controller.CreateAsync(candidate, query);

            Assert.Equal(id, user.Id);
        }
        public async Task CreateAsyncShouldNotCallGetByIdsOnTheCollection()
        {
            var users      = new UsersCollectionWithHardcodedGetById(_fixture.UsersRepo, _fixture.PatcherProvider, _fixture.Instanciator);
            var controller = new UsersAppController(_fixture.InMemoryStorage, users);
            var id1        = Guid.NewGuid();
            var id2        = Guid.NewGuid();

            var result = (await controller.CreateAsync(new List <User> {
                new User {
                    Id = id1
                }, new User {
                    Id = id2
                }
            })).ToList();

            Assert.Equal(id1, result[0].Id);
            Assert.Equal(id2, result[1].Id);
        }
        public async Task Put_SHOULD_NOT_throw_notfound_exception_WHEN_unexisting_entity_()
        {
            Expression <Func <User, bool> > trueFilter = t => true;
            var rightService = new Mock <IRightExpressionsHelper <User> >();

            rightService.Setup(s => s.GetFilterAsync(It.IsAny <Query <User> >())).Returns(Task.FromResult(trueFilter));

            var id         = Guid.NewGuid();
            var repo       = new Repository <User>(_fixture.InMemoryStorage, rightService.Object, _fixture.IncludeApplicator);
            var users      = new UsersCollection(repo, _fixture.PatcherProvider, _fixture.Instanciator);
            var app        = new UsersAppController(_fixture.InMemoryStorage, users);
            var candidate1 = _parser.Parse <User, Guid>($@"{{ ""id"": ""{id}"" }}");
            var candidate2 = _parser.Parse <User, Guid>(@"{ ""name"": ""new name"" }");

            await app.CreateAsync(candidate1, new Query <User>());

            await app.UpdateByIdAsync(Guid.NewGuid(), candidate2, new Query <User>());
        }
        public async Task PostShouldNotCallGetByIdsOnTheCollection()
        {
            var users      = new UsersCollectionWithHardcodedGetById(_fixture.UsersRepo, _fixture.PatcherProvider, _fixture.Instanciator);
            var controller = new UsersAppController(_fixture.InMemoryStorage, users);
            var query      = new Query <User> {
                Verb = Helpers.HttpVerbs.Post
            };
            var id1        = Guid.NewGuid();
            var id2        = Guid.NewGuid();
            var candidate1 = _parser.Parse <User, Guid>($@"{{ ""id"": ""{id1}"" }}");
            var candidate2 = _parser.Parse <User, Guid>($@"{{ ""id"": ""{id2}"" }}");

            var result = (await controller.CreateAsync(new List <ICandidate <User, Guid> > {
                candidate1, candidate2
            }, query)).ToList();

            Assert.Equal(id1, result[0].Id);
            Assert.Equal(id2, result[1].Id);
        }
        public async Task CreateAsyncCollectionShouldWorkIfForbiddenButExplicitelyAllowed()
        {
            var repo       = new Repository <User>(_fixture.InMemoryStorage, new ClosedRightExpressionsHelper <User>(), _fixture.IncludeApplicator);
            var users      = new UsersCollectionWithHardcodedGetById(repo, _fixture.PatcherProvider, _fixture.Instanciator);
            var controller = new UsersAppController(_fixture.InMemoryStorage, users);
            var id1        = Guid.NewGuid();
            var id2        = Guid.NewGuid();

            var result = (await controller.CreateAsync(new List <User> {
                new User {
                    Id = id1
                }, new User {
                    Id = id2
                }
            }, false)).ToList();

            Assert.Equal(id1, result[0].Id);
            Assert.Equal(id2, result[1].Id);
        }
        public async Task PostOnCollectionShouldWorkIfForbiddenButExplicitelyAllowed()
        {
            var repo       = new Repository <User>(_fixture.InMemoryStorage, new ClosedRightExpressionsHelper <User>(), _fixture.IncludeApplicator);
            var users      = new UsersCollectionWithHardcodedGetById(repo, _fixture.PatcherProvider, _fixture.Instanciator);
            var controller = new UsersAppController(_fixture.InMemoryStorage, users);
            var query      = new Query <User>();

            query.Options.ChecksRights = false;
            var id1        = Guid.NewGuid();
            var id2        = Guid.NewGuid();
            var candidate1 = _parser.Parse <User, Guid>($@"{{ ""id"": ""{id1}"" }}");
            var candidate2 = _parser.Parse <User, Guid>($@"{{ ""id"": ""{id2}"" }}");

            var result = (await controller.CreateAsync(new List <ICandidate <User, Guid> > {
                candidate1, candidate2
            }, query)).ToList();

            Assert.Equal(id1, result[0].Id);
            Assert.Equal(id2, result[1].Id);
        }