public async Task GetLogoShouldReturnDefaultLogo() { using (var mockContext = new MockHttpContext()) { this.controller.ControllerContext.HttpContext = mockContext.Object; this.mockStorage .Setup(x => x.GetLogoAsync()) .ReturnsAsync(new Logo { Image = Logo.Default.Image, Type = Logo.Default.Type, IsDefault = true }); await this.controller.GetLogoAsync(); this.mockStorage .Verify(x => x.GetLogoAsync(), Times.Once); Assert.Equal(Logo.Default.Image, mockContext.GetBody()); Assert.Equal(Logo.Default.Type, mockContext.Object.Response.ContentType); Assert.Equal("True", mockContext.GetHeader(Logo.IS_DEFAULT_HEADER)); } }
public async Task GetLogoShouldReturnExpectedNameAndType() { var image = this.rand.NextString(); var type = this.rand.NextString(); var name = this.rand.NextString(); using (var mockContext = new MockHttpContext()) { this.controller.ControllerContext.HttpContext = mockContext.Object; this.mockStorage .Setup(x => x.GetLogoAsync()) .ReturnsAsync(new Logo { Image = image, Type = type, Name = name, IsDefault = false }); await this.controller.GetLogoAsync(); this.mockStorage .Verify(x => x.GetLogoAsync(), Times.Once); Assert.Equal(image, mockContext.GetBody()); Assert.Equal(type, mockContext.Object.Response.ContentType); Assert.Equal(name, mockContext.GetHeader(Logo.NAME_HEADER)); Assert.Equal("False", mockContext.GetHeader(Logo.IS_DEFAULT_HEADER)); } }
public async Task SetLogoShouldReturnGivenLogoAndName() { var image = this.rand.NextString(); var type = this.rand.NextString(); var name = this.rand.NextString(); using (var mockContext = new MockHttpContext()) { this.controller.ControllerContext.HttpContext = mockContext.Object; this.mockStorage .Setup(x => x.SetLogoAsync(It.IsAny <Logo>())) .ReturnsAsync((Logo logo) => logo); mockContext.Object.Request.ContentType = type; mockContext.SetBody(image); mockContext.SetHeader(Logo.NAME_HEADER, name); await this.controller.SetLogoAsync(); this.mockStorage .Verify(x => x.SetLogoAsync( It.Is <Logo>(m => m.Image == image && m.Type == type && m.Name == name && !m.IsDefault)), Times.Once); Assert.Equal(image, mockContext.GetBody()); Assert.Equal(type, mockContext.Object.Response.ContentType); Assert.Equal(name, mockContext.GetHeader(Logo.NAME_HEADER)); Assert.Equal("False", mockContext.GetHeader(Logo.IS_DEFAULT_HEADER)); } }
public async Task GetLogoAsyncTest() { var image = this.rand.NextString(); var type = this.rand.NextString(); using (var mockContext = new MockHttpContext()) { this.controller.ControllerContext.HttpContext = mockContext.Object; this.mockStorage .Setup(x => x.GetLogoAsync()) .ReturnsAsync(new Logo { Image = image, Type = type }); await this.controller.GetLogoAsync(); this.mockStorage .Verify(x => x.GetLogoAsync(), Times.Once); Assert.Equal(mockContext.GetBody(), image); Assert.Equal(mockContext.GetHeader("content-type"), type); } }