Beispiel #1
0
        public async Task <UserRatingDto> GetUserRatingAsync(int idForRestApi)
        {
            var url  = RequestPath + idForRestApi;
            var json = await contentApiClient.GetResponseFromUrlAsString(url);

            return(JsonConvert.DeserializeObject <UserRatingDto>(json));
        }
Beispiel #2
0
        public async Task GetMedias_SingleMedia()
        {
            var    sut        = CreateSystemUnderTest();
            string jsonReturn = "{" +
                                "total: 1," +
                                "items: [" +
                                "{" +
                                "\"id\": 1, " +
                                "\"title\": \"Test Title\"," +
                                "\"description\": \"Test Description\"," +
                                "\"type\": \"image\"," +
                                "\"timestamp\": \"2017-05-29T10:10:10.10+00:00\"," +
                                "\"status\": \"Test Status\"," +
                                "\"used\": true" +
                                "}" +
                                "]" +
                                "}";

            contentApiSubstitute.GetResponseFromUrlAsString(null).ReturnsForAnyArgs(jsonReturn);

            var medias = await sut.GetMedias();

            Assert.AreEqual(1, medias.Total);
            Assert.AreEqual(1, medias.Items.Count);

            var firstMedia = medias.Items[0];

            Assert.AreEqual(1, firstMedia.Id);
            Assert.AreEqual("Test Title", firstMedia.Title);
            Assert.AreEqual("Test Description", firstMedia.Description);
            Assert.AreEqual("Test Status", firstMedia.Status);
            Shared.Helpers.AssertionHelper.AreEqual(new DateTimeOffset(2017, 5, 29, 10, 10, 10, 10, TimeSpan.Zero), firstMedia.Timestamp);
            Assert.AreEqual(true, firstMedia.Used);
        }
Beispiel #3
0
        public async Task <IEnumerable <AchievementDto> > GetUnlockedAchievements()
        {
            const string requestPath = "/Achievements/Unlocked";
            var          json        = await contentApiClient.GetResponseFromUrlAsString(requestPath);

            return(ParseAchievementsJson(json));
        }
Beispiel #4
0
        private async Task <RoutesDto> GetRoutesDto(DateTimeOffset?timestamp, IList <int> includeOnly)
        {
            string requestPath = @"/Routes";

            requestPath += UriQueryBuilder.GetAdditionalParametersQuery(timestamp, includeOnly);

            string json = await contentApiClient.GetResponseFromUrlAsString(requestPath);

            return(JsonConvert.DeserializeObject <RoutesDto>(json));
        }
Beispiel #5
0
        public async Task GetRoutes_SingleRoute()
        {
            var    sut        = CreateSystemUnderTest();
            string jsonReturn = "{" +
                                "total: 1," +
                                "items: [" +
                                "{" +
                                "\"id\": 1," +
                                "\"title\": \"Test Title\"," +
                                "\"description\": \"Test Description\"," +
                                "\"duration\": 1800," +
                                "\"distance\": 4.2," +
                                "\"image\": 42," +
                                "\"audio\": 103," +
                                "\"exhibits\": [ 1, 2, 3, 5, 6 ]," +
                                "\"status\": \"Test Status\"," +
                                "\"tags\": [ 2, 4 ]," +
                                "\"timestamp\": \"2017-05-29T10:10:10.10+00:00\"" +
                                "}" +
                                "]" +
                                "}";

            contentApiSubstitute.GetResponseFromUrlAsString(null).ReturnsForAnyArgs(jsonReturn);

            var routes = await sut.GetRoutes();

            Assert.AreEqual(1, routes.Total);
            Assert.AreEqual(1, routes.Items.Count);

            var firstRoute = routes.Items[0];

            Assert.AreEqual(1, firstRoute.Id);
            Assert.AreEqual("Test Title", firstRoute.Title);
            Assert.AreEqual("Test Description", firstRoute.Description);
            Assert.AreEqual(42, firstRoute.Image);
            Assert.AreEqual(1800, firstRoute.Duration);
            Assert.AreEqual(4.2, firstRoute.Distance);
            Assert.AreEqual(103, firstRoute.Audio);

            Assert.AreEqual("Test Status", firstRoute.Status);
            Shared.Helpers.AssertionHelper.AreEqual(new DateTimeOffset(2017, 5, 29, 10, 10, 10, 10, TimeSpan.Zero), firstRoute.Timestamp);

            Assert.AreEqual(2, firstRoute.Tags.Count);
            Assert.AreEqual(2, firstRoute.Tags[0]);
            Assert.AreEqual(4, firstRoute.Tags[1]);

            Assert.AreEqual(5, firstRoute.Exhibits.Count);
            Assert.AreEqual(1, firstRoute.Exhibits[0]);
            Assert.AreEqual(2, firstRoute.Exhibits[1]);
            Assert.AreEqual(3, firstRoute.Exhibits[2]);
            Assert.AreEqual(5, firstRoute.Exhibits[3]);
            Assert.AreEqual(6, firstRoute.Exhibits[4]);
        }
Beispiel #6
0
        public async Task GetExhibits_SingleExhibit()
        {
            var    sut        = CreateSystemUnderTest();
            string jsonReturn = "{" +
                                "total: 1," +
                                "items: [" +
                                "{" +
                                "\"id\": 1," +
                                "\"name\": \"Test Name\"," +
                                "\"description\": \"Test Description\"," +
                                "\"image\": 42," +
                                "\"latitude\": 42.7," +
                                "\"longitude\": 42.8," +
                                "\"status\": \"Test Status\"," +
                                "\"tags\": [1, 3]," +
                                "\"pages\": [4, 5, 7]," +
                                "\"timestamp\": \"2017-05-29T10:10:10.10+00:00\"," +
                                "\"used\": true" +
                                "}" +
                                "]" +
                                "}";

            contentApiSubstitute.GetResponseFromUrlAsString(null).ReturnsForAnyArgs(jsonReturn);

            var exhibits = await sut.GetExhibits();

            Assert.AreEqual(1, exhibits.Total);
            Assert.AreEqual(1, exhibits.Items.Count);

            var firstExhibit = exhibits.Items[0];

            Assert.AreEqual(1, firstExhibit.Id);
            Assert.AreEqual("Test Name", firstExhibit.Name);
            Assert.AreEqual("Test Description", firstExhibit.Description);
            Assert.AreEqual(42, firstExhibit.Image);
            Assert.AreEqual(42.7, firstExhibit.Latitude);
            Assert.AreEqual(42.8, firstExhibit.Longitude);
            Assert.AreEqual("Test Status", firstExhibit.Status);
            Shared.Helpers.AssertionHelper.AreEqual(new DateTimeOffset(2017, 5, 29, 10, 10, 10, 10, TimeSpan.Zero), firstExhibit.Timestamp);
            Assert.AreEqual(true, firstExhibit.Used);

            Assert.AreEqual(2, firstExhibit.Tags.Count);
            Assert.AreEqual(1, firstExhibit.Tags[0]);
            Assert.AreEqual(3, firstExhibit.Tags[1]);

            Assert.AreEqual(3, firstExhibit.Pages.Count);
            Assert.AreEqual(4, firstExhibit.Pages[0]);
            Assert.AreEqual(5, firstExhibit.Pages[1]);
            Assert.AreEqual(7, firstExhibit.Pages[2]);
        }
        public async Task <IList <FeatureDto> > GetEnabledFeaturesAsync()
        {
            const string requestPath = "/Features/IsEnabled";
            var          json        = await contentApiClient.GetResponseFromUrlAsString(requestPath);

            return(JsonConvert.DeserializeObject <IList <FeatureDto> >(json));
        }
Beispiel #8
0
        public async Task <List <QuizDto> > GetQuestionsForExhibitAsync(int exhibitId)
        {
            var requestPath = $"/Exhibits/{exhibitId}/Questions";
            var json        = await apiClient.GetResponseFromUrlAsString(requestPath);

            return(JsonConvert.DeserializeObject <List <QuizDto> >(json));
        }
Beispiel #9
0
        public async Task GetUserRating()
        {
            var json = "{" +
                       "\"id\": 1," +
                       "\"average\": 3.5," +
                       "\"count\": 24," +
                       "\"ratingTable\": {" +
                       "\"1\": 2," +
                       "\"2\": 4," +
                       "\"3\": 6," +
                       "\"4\": 4," +
                       "\"5\": 8" +
                       "}" +
                       "}";

            contentApiSubstitute.GetResponseFromUrlAsString(null).ReturnsForAnyArgs(json);

            var userRatingDto = await client.GetUserRatingAsync(0);

            Assert.NotNull(userRatingDto);
            Assert.AreEqual(userRatingDto.Id, 1);
            Assert.AreEqual(userRatingDto.Average, 3.5);
            Assert.AreEqual(userRatingDto.Count, 24);
            Assert.NotNull(userRatingDto.RatingTable);
            Assert.AreEqual(userRatingDto.RatingTable[1], 2);
            Assert.AreEqual(userRatingDto.RatingTable[2], 4);
            Assert.AreEqual(userRatingDto.RatingTable[3], 6);
            Assert.AreEqual(userRatingDto.RatingTable[4], 4);
            Assert.AreEqual(userRatingDto.RatingTable[5], 8);
        }
Beispiel #10
0
        private async Task <PagesDto> GetPagesDtoWithExhibitConstraint(int exhibitId, DateTimeOffset?timestamp, IList <int> includeOnly)
        {
            string requestPath = $@"/Exhibits/{exhibitId}/Pages";

            requestPath += UriQueryBuilder.GetAdditionalParametersQuery(timestamp, includeOnly);

            string json = await contentApiClient.GetResponseFromUrlAsString(requestPath);

            if (json != null)
            {
                return(JsonConvert.DeserializeObject <PagesDto>(json));
            }

            return(new PagesDto {
                Items = new List <PageDto>(), Total = 0
            });
        }
Beispiel #11
0
        private async Task <MediasDto> GetMediasDto(DateTimeOffset?timestamp, IList <int> includeOnly)
        {
            string requestPath = @"/Media";

            requestPath += UriQueryBuilder.GetAdditionalParametersQuery(timestamp, includeOnly);

            string json = await contentApiClient.GetResponseFromUrlAsString(requestPath);

            if (json != null)
            {
                return(JsonConvert.DeserializeObject <MediasDto>(json));
            }

            return(new MediasDto {
                Items = new List <MediaDto>(), Total = 0
            });
        }
Beispiel #12
0
        public async Task GetPages_ImagePage()
        {
            var    sut        = CreateSystemUnderTest();
            string jsonReturn = "{" +
                                "total: 1," +
                                "items: [" +
                                "{" +
                                "\"exhibitId\": 17," +
                                "\"id\": 1," +
                                "\"type\": \"imagepage\"," +
                                "\"image\": 42," +
                                "\"audio\": 17," +
                                "\"status\": \"Test Status\"," +
                                "\"timestamp\": \"2017-05-29T10:10:10.10+00:00\"," +
                                "\"additionalInformationPages\": [4, 5]" +
                                "}" +
                                "]" +
                                "}";

            contentApiSubstitute.GetResponseFromUrlAsString(null).ReturnsForAnyArgs(jsonReturn);

            var pages = await sut.GetPages();

            Assert.AreEqual(1, pages.Total);
            Assert.AreEqual(1, pages.Items.Count);

            var firstPage = pages.Items[0];

            Assert.AreEqual(1, firstPage.Id);
            Assert.AreEqual(17, firstPage.ExhibitId);
            Assert.AreEqual(42, firstPage.Image);
            Assert.AreEqual(17, firstPage.Audio);
            Assert.AreEqual(PageTypeDto.ImagePage, firstPage.Type);

            var additionalInformationPages = firstPage.AdditionalInformationPages;

            Assert.AreEqual(2, additionalInformationPages.Count);
            Assert.AreEqual(4, additionalInformationPages[0]);
            Assert.AreEqual(5, additionalInformationPages[1]);

            Assert.AreEqual("Test Status", firstPage.Status);
            Shared.Helpers.AssertionHelper.AreEqual(new DateTimeOffset(2017, 5, 29, 10, 10, 10, 20, TimeSpan.Zero), firstPage.Timestamp);
        }
Beispiel #13
0
        public async Task GetEnabledFeaturesTest()
        {
            var json = @"
                [
                    {
                        ""id"": 4,
                        ""name"": ""Mein neues Feature"",
                        ""parent"": null,
                        ""children"": [],
                        ""groupsWhereEnabled"": [
                            1,
                            2
                        ]
                    },
                    {
                        ""id"": 6,
                        ""name"": ""Feature Beta"",
                        ""parent"": null,
                        ""children"": [],
                        ""groupsWhereEnabled"": [
                            1,
                            2
                        ]
                    }
                ]";

            contentApiSubstitute.GetResponseFromUrlAsString(null).ReturnsForAnyArgs(json);
            var fetchedDtos = (await client.GetEnabledFeaturesAsync()).ToList();
            var checkDtos   = new List <FeatureDto>
            {
                new FeatureDto(4, "Mein neues Feature", null, new List <int>(), new List <int> {
                    1, 2
                }),
                new FeatureDto(6, "Feature Beta", null, new List <int>(), new List <int> {
                    1, 2
                })
            };

            Assert.AreEqual(fetchedDtos.Count, checkDtos.Count);
            for (var i = 0; i < checkDtos.Count; i++)
            {
                var checkDto   = checkDtos[i];
                var fetchedDto = fetchedDtos[i];

                Assert.AreEqual(checkDto.Id, fetchedDto.Id);
                Assert.AreEqual(checkDto.Name, fetchedDto.Name);
                Assert.AreEqual(checkDto.ChildrenFeatureIds, fetchedDto.ChildrenFeatureIds);
                Assert.AreEqual(checkDto.ParentFeatureId, fetchedDto.ParentFeatureId);
                Assert.AreEqual(checkDto.GroupIdsWhereEnabled, fetchedDto.GroupIdsWhereEnabled);
            }
        }
        public async Task GetAchievements()
        {
            var json = "{\"total\":2," +
                       "\"items\":[" +
                       "{\"routeId\":0,\"id\":0,\"type\":\"RouteFinished\",\"status\":\"PUBLISHED\"," +
                       "\"title\":\"Finish Karls Route\",\"description\":" +
                       "\"Visit all exhibits on this route to unlock this achievement\"," +
                       "\"thumbnailUrl\": \"achievements/api/image/0/\"," +
                       "\"nextId\":0,\"points\":1," +
                       "\"userId\":\"auth0|5968ed8cdd1b3733ca94865d\",\"timestamp\":\"2017-10-23T13:28:43.6293372+00:00\"}," +
                       "{\"count\":10,\"id\":1,\"type\":\"ExhibitsVisited\",\"status\":\"PUBLISHED\"," +
                       "\"title\":\"Visit 10 exhibits\",\"description\":" +
                       "\"Visit 10 exhibits to unlock this achievement\"," +
                       "\"thumbnailUrl\": \"achievements/api/image/0/\"," +
                       "\"nextId\":0,\"points\":1," +
                       "\"userId\":\"auth0|5968ed8cdd1b3733ca94865d\",\"timestamp\":\"2017-10-23T13:27:55.427995+00:00\"}]}";

            contentApiSubstitute.GetResponseFromUrlAsString(null).ReturnsForAnyArgs(json);

            var achievementDtos = (await client.GetUnlockedAchievements()).ToList();
            var routeFinished   = achievementDtos[0] as RouteFinishedAchievementDto;
            var exhibitsVisited = achievementDtos[1] as ExhibitsVisitedAchievementDto;

            Assert.NotNull(routeFinished);
            Assert.AreEqual(routeFinished.Id, 0);
            Assert.AreEqual(routeFinished.Title, "Finish Karls Route");
            Assert.AreEqual(routeFinished.Description, "Visit all exhibits on this route to unlock this achievement");
            Assert.AreEqual(routeFinished.ThumbnailUrl, "achievements/api/image/0/");
            Assert.AreEqual(routeFinished.NextId, 0);
            Assert.AreEqual(routeFinished.Points, 1);
            Assert.AreEqual(routeFinished.RouteId, 0);

            Assert.NotNull(exhibitsVisited);
            Assert.AreEqual(exhibitsVisited.Id, 1);
            Assert.AreEqual(exhibitsVisited.Title, "Visit 10 exhibits");
            Assert.AreEqual(exhibitsVisited.Description, "Visit 10 exhibits to unlock this achievement");
            Assert.AreEqual(exhibitsVisited.ThumbnailUrl, "achievements/api/image/0/");
            Assert.AreEqual(exhibitsVisited.NextId, 0);
            Assert.AreEqual(exhibitsVisited.Count, 10);
            Assert.AreEqual(exhibitsVisited.Points, 1);
        }