예제 #1
0
        public async Task CanUpdateMessagesReadStatus()
        {
            var factory = _factoryCollection.ForUpdate;

            using (var httpClient = await factory.CreateClientWithAccessTokenAsync(USER_NAME))
            {
                int expectedCount = 3;
                var model         = new MessageReadStatusBindingModel
                {
                    MessageIds = new int[] { 1, 2 },
                    IsRead     = false
                };
                string json    = JsonConvert.SerializeObject(model);
                var    content = new StringContent(json, Encoding.UTF8, "application/json");
                using (var response = await httpClient.PutAsync(BASE_URL, content))
                {
                    Assert.True(response.IsSuccessStatusCode);
                    Assert.Equal("application/json", response.Content.Headers.ContentType.MediaType);
                    string responseJson = await response.Content.ReadAsStringAsync();

                    var details = JsonConvert.DeserializeObject <OperationDetails>(responseJson);
                    Assert.False(details.IsError);
                    Assert.Equal($"A set of entities of type '{typeof(Message)}' has been updated successfully.", details.Message);
                    using (var scope = factory.Server.Host.Services.CreateScope())
                    {
                        using (var db = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>())
                        {
                            Assert.Equal(expectedCount, db.Messages.Where(x => x.IsRead == false).Count());
                        }
                    }
                }
            }
        }
        public async Task UpdateReadStatusAsync_Good()
        {
            var testModel = new MessageReadStatusBindingModel
            {
                MessageIds = new int[3],
                IsRead     = false
            };

            var actionResult = await _target.UpdateReadStatusAsync(testModel);

            _mockMessageService.Verify(x => x.UpdateMessageReadStatusAsync(It.IsAny <int>(), false), Times.Exactly(3));
            Assert.IsType <OkObjectResult>(actionResult);
            var result = actionResult as OkObjectResult;

            Assert.Equal(200, result.StatusCode);
            Assert.IsType <OperationDetails>(result.Value);
            var details = result.Value as OperationDetails;

            Assert.False(details.IsError);
            Assert.Equal($"A set of entities of type '{typeof(Message)}' has been updated successfully.",
                         details.Message);
        }