Ejemplo n.º 1
0
        public async Task UploadFile_Accepted()
        {
            var client = await _factory.CreateAuthenticatedClient();

            _fileMetadataRepository.CreateFileMetadata(Arg.Any <FileMetadata>())
            .Returns(call => call.Arg <FileMetadata>());

            var fileBytes = Encoding.UTF8.GetBytes("test");
            var fileName  = "image.png";
            var response  = await client.PostAsync("/api/v2/file", new MultipartFormDataContent
            {
                { new ByteArrayContent(fileBytes), "files", fileName },
                { new ByteArrayContent(Encoding.UTF8.GetBytes("test2")), "files", "image2.jpg" }
            });

            var uploadedFiles = await response.EnsureSuccessStatusCode()
                                .Content.ReadAsAsync <List <FileMetadata> >();

            Assert.Equal(2, uploadedFiles.Count);

            var file = uploadedFiles.First();

            Assert.Equal(fileName, file.Name);
            Assert.Equal(fileBytes.Length, file.FileSize);
        }
        public async Task GetChannels_Existing_Ok()
        {
            var appId  = Guid.NewGuid();
            var client = await _factory.CreateAuthenticatedClient();

            _applicationRepository.Get(appId).Returns(new Application
            {
                Id       = appId,
                Channels = new List <Channel>
                {
                    new Channel {
                        Id = Guid.NewGuid(), Name = "B"
                    },
                    new Channel {
                        Id = Guid.NewGuid(), Name = "A"
                    }
                }
            });

            var response = await client.GetAsync($"/api/v2/app/{appId}/channel");

            var retrievedChannels = await response.EnsureSuccessStatusCode()
                                    .Content.ReadAsAsync <List <Channel> >();

            Assert.Equal(new[] { "A", "B" }, retrievedChannels.Select(channel => channel.Name));
        }
        public async Task Get_ExistingChannel_Ok()
        {
            var appId     = Guid.NewGuid();
            var channelId = Guid.NewGuid();
            var client    = await _factory.CreateAuthenticatedClient();

            _messageRepository.GetAll(appId, channelId, Arg.Any <int>())
            .Returns(new[] { new Message(), new Message() });

            var response = await client.GetAsync($"/api/v2/app/{appId}/channel/{channelId}/message");

            var retrievedMessages = await response.EnsureSuccessStatusCode().Content.ReadAsAsync <List <Message> >();

            Assert.Equal(2, retrievedMessages.Count);
        }
Ejemplo n.º 4
0
        public async Task GetApplicationUsers_Existing_Ok()
        {
            var appId = Guid.NewGuid();

            _userRepository.Get(appId)
            .Returns(new[] { new User(), new User(), new User() });

            var client = await _factory.CreateAuthenticatedClient(_userRepository);

            var response = await client.GetAsync($"/api/v2/{appId}/user");

            var users = await response.EnsureSuccessStatusCode()
                        .Content.ReadAsAsync <List <User> >();

            Assert.Equal(3, users.Count);
        }
Ejemplo n.º 5
0
        public async Task Update_ExistingApp_Ok()
        {
            var client = await _factory.CreateAuthenticatedClient();

            var appId = Guid.NewGuid();

            _applicationRepositoryMock.Get(appId)
            .Returns(new Application {
                Id = appId
            });
            _applicationRepositoryMock.Upsert(Arg.Any <Application>())
            .Returns(call => call.Arg <Application>());

            var newCustomData = JObject.FromObject(new { json = true });
            var response      = await client.PutAsync($"/api/v2/app/{appId}", new JsonContent(new ApplicationUpdate
            {
                CustomData = newCustomData
            }));

            var updatedApp = await response.EnsureSuccessStatusCode()
                             .Content.ReadAsAsync <ApplicationResponse>();

            Assert.Equal(appId, updatedApp.Id);
            Assert.Equal(newCustomData, updatedApp.CustomData);
        }
Ejemplo n.º 6
0
 public static HttpClient CreateAuthenticatedClient <T>(this WebApplicationFactory <T> factory) where T : class
 {
     return(factory.CreateAuthenticatedClient(TestData.NewString(), TestData.NewString()));
 }
Ejemplo n.º 7
0
 public static HttpClient CreateAuthenticatedClient <T>(this WebApplicationFactory <T> factory, Player p) where T : class
 {
     return(factory.CreateAuthenticatedClient(p.AuthProviderId, p.Email));
 }