public async Task Get_Should_Return_Error_When_Exception_Was_Thrown(Type exceptionType) { // Arrange. var manager = new Mock <ITemplateManager>(); manager.Setup(m => m.GetTemplate(It.IsAny <string>())) .Throws((Exception)Activator.CreateInstance(exceptionType)); MessageTemplatesController controller = GetController(manager); // Act. var result = await Assert.ThrowsAnyAsync <Exception>(() => controller.Get(TemplateName)); // Assert. Assert.Equal(exceptionType, result.GetType()); }
public async Task Get_Should_Return_Valid_Template() { // Arrange. var template = new MessageTemplate(); var manager = new Mock <ITemplateManager>(); manager.Setup(m => m.GetTemplate(It.IsAny <string>())) .ReturnsAsync(template); MessageTemplatesController controller = GetController(manager); // Act. ActionResult <MessageTemplate> result = await controller.Get(TemplateName); // Assert. Assert.Equal(template, result.Value); }