Beispiel #1
0
        public async Task TestQueryAsync_ServerReturnsQuery_ReturnsListWithSurveyResources()
        {
            var expectedSurveyResources = new List <SurveyResource>();

            for (var i = 0; i < 5; i++)
            {
                var surveyResource = new SurveyResource
                {
                    SurveyId               = Guid.NewGuid().ToString(),
                    SurveyName             = $"Survey{i}",
                    Owner                  = $"Owner{i}",
                    ClientName             = $"Client{i}",
                    Size                   = i,
                    CreationDate           = new DateTime(2020, 1, 1),
                    LastDataDownloadDate   = new DateTime(2020, 1, 2),
                    LastDataCollectionDate = new DateTime(2020, 1, 3),
                    State                  = SurveyStatus.UnderConstruction,
                    Channel                = SurveyChannel.Online
                };

                expectedSurveyResources.Add(surveyResource);
            }

            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient
            .Setup(client => client.GetAsync(new Uri(ServiceAddress, "SurveyResources/")))
            .Returns(CreateTask(HttpStatusCode.OK,
                                new StringContent(JsonConvert.SerializeObject(expectedSurveyResources))));

            var target = new NfieldSurveyResourcesService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actualSurveyResources = await target.QueryAsync();

            Assert.Equal(5, actualSurveyResources.Count());

            for (var i = 0; i < 5; i++)
            {
                var actualSurveyResource   = actualSurveyResources.ElementAt(i);
                var expectedSurveyResource = expectedSurveyResources[i];

                Assert.Equal(expectedSurveyResource.SurveyId, actualSurveyResource.SurveyId);
                Assert.Equal(expectedSurveyResource.SurveyName, actualSurveyResource.SurveyName);
                Assert.Equal(expectedSurveyResource.Owner, actualSurveyResource.Owner);
                Assert.Equal(expectedSurveyResource.Size, actualSurveyResource.Size);
                Assert.Equal(expectedSurveyResource.CreationDate, actualSurveyResource.CreationDate);
                Assert.Equal(expectedSurveyResource.LastDataDownloadDate, actualSurveyResource.LastDataDownloadDate);
                Assert.Equal(expectedSurveyResource.LastDataCollectionDate, actualSurveyResource.LastDataCollectionDate);
                Assert.Equal(expectedSurveyResource.State, actualSurveyResource.State);
                Assert.Equal(expectedSurveyResource.Channel, actualSurveyResource.Channel);
            }
        }
Beispiel #2
0
        public OperationResult.SeeOther Post(NewSurveyResource resource)
        {
            var s = repository.Create(resource.Name, resource.Title, resource.Description);
            var r = new SurveyResource {
                Id = s.Id, Name = s.Name, Title = s.Title, Description = s.Description
            };

            return(new OperationResult.SeeOther {
                RedirectLocation = r.CreateUri()
            });
        }
Beispiel #3
0
        public OperationResult Put(SurveyResource resource)
        {
            var s = repository.GetSurvey(resource.Id);

            s.Name        = resource.Name;
            s.Title       = resource.Title;
            s.Description = resource.Description;
            repository.Update(s);

            return(new OperationResult.SeeOther {
                RedirectLocation = resource.CreateUri()
            });
        }