public async Task ShouldRequestAnItemFromTheApi()
        {
            var client = Mock.Of <ApiClient>();

            var item = new RegistrationGroup();

            int itemId = 1;

            Mock.Get(client).Setup(c => c.GetObject <RegistrationGroup>(
                                       $"registration_groups/{itemId}",
                                       It.IsAny <ExpandoObject>())).Returns(Task.FromResult(item)).Verifiable();

            var registrationGroupResource = new RegistrationGroupsResource(client);
            var result = await registrationGroupResource.Find(itemId);

            Mock.Get(client).VerifyAll();
        }
        public async Task ShouldRequestAllFromTheApi()
        {
            var client = Mock.Of <ApiClient>();

            IList <RegistrationGroup> groups = new List <RegistrationGroup>()
            {
                new RegistrationGroup(), new RegistrationGroup()
            };

            Mock.Get(client).Setup(c => c.GetList <RegistrationGroup>(RegistrationGroupsResource.ResourceName, It.IsAny <ExpandoObject>())).Returns(Task.FromResult(groups));

            var resource = new RegistrationGroupsResource(client);

            await resource.All();

            Mock.Get(client).VerifyAll();
        }
        public async Task ShouldRequestListFromTheApiWithOnlySomeParameters()
        {
            var client = Mock.Of <ApiClient>();

            IList <RegistrationGroup> groups = new List <RegistrationGroup>()
            {
                new RegistrationGroup(), new RegistrationGroup()
            };

            Mock.Get(client).Setup(c => c.GetList <RegistrationGroup>(
                                       "registration_groups",
                                       It.Is <ExpandoObject>(x => x.V("year_code") == null))).Returns(Task.FromResult(groups)).Verifiable();

            var registrationGroupResource = new RegistrationGroupsResource(client);
            var results = await registrationGroupResource.List();

            Assert.That(results.Count, Is.EqualTo(groups.Count));

            Mock.Get(client).VerifyAll();
        }
        public async Task ShouldRequestListFromTheApiWithAllParameters()
        {
            var client = Mock.Of <ApiClient>();

            IList <RegistrationGroup> registrationGroups = new List <RegistrationGroup>()
            {
                new RegistrationGroup(), new RegistrationGroup()
            };

            var yearCode = "a";

            Mock.Get(client).Setup(c => c.GetList <RegistrationGroup>(
                                       RegistrationGroupsResource.ResourceName,
                                       It.Is <ExpandoObject>(x =>
                                                             x.V <string>("year_code") == "a"))).Returns(Task.FromResult(registrationGroups)).Verifiable();

            var resource = new RegistrationGroupsResource(client);
            var results  = await resource.List(yearCode : yearCode);

            Assert.That(results.Count, Is.EqualTo(registrationGroups.Count));

            Mock.Get(client).VerifyAll();
        }
        public async Task RegistrationGroupFetchesStudents()
        {
            IList <Student> groups = new List <Student>()
            {
                new Student(), new Student()
            };

            var client = Mock.Of <ApiClient>();

            var resource = new RegistrationGroupsResource(client);

            var registrationGroup = new RegistrationGroup();

            registrationGroup.Resource = resource;

            var resourceAddress = $"{RegistrationGroupsResource.ResourceName}/{registrationGroup.Id}/students";

            Mock.Get(client).Setup(c => c.GetList <Student>(resourceAddress, It.IsAny <ExpandoObject>())).Returns(Task.FromResult(groups));

            var results = await registrationGroup.Students();

            Assert.That(results.First().FirstName, Is.EqualTo(groups.First().FirstName));
        }