public async Task HandleExtraSpacesBetweenKeywordAndNumber() { var mockRequest = new Mock <HttpRequest>(); var mockLogger = new Mock <ILogger>(); var mockFileWrapper = new Mock <IHelpers>(); var assembly = Assembly.LoadFrom("CalculatorFunction"); mockFileWrapper.Setup(m => m.LoadInstructionsfromFile(assembly, "CalculatorFunction.Instructions.txt")).Returns("add 10\r\nmultiply 2\r\nsubtract 5\r\napply 2"); var function = new CalculatorFunction.CalculatorFunction(mockFileWrapper.Object); var result = await function.Calculator(mockRequest.Object, mockLogger.Object); var request = new CalculatorResponse { Result = 19 }; var objectResult = result as ObjectResult; var value = objectResult.Value as CalculatorResponse; Xunit.Assert.Equal(value.Result, request.Result); Xunit.Assert.Equal(200, objectResult?.StatusCode.Value); }
public async Task InvalidRequest_InstructionFileNotFound() { var mockRequest = new Mock <HttpRequest>(); var mockLogger = new Mock <ILogger>(); var mockFileWrapper = new Mock <IHelpers>(); var assembly = Assembly.LoadFrom("CalculatorFunction"); mockFileWrapper.Setup(m => m.LoadInstructionsfromFile(assembly, "CalculatorFunction.Instruction.txt")); var function = new CalculatorFunction.CalculatorFunction(mockFileWrapper.Object); var result = await function.Calculator(mockRequest.Object, mockLogger.Object); var objectResult = result as ObjectResult; Xunit.Assert.Equal(400, objectResult?.StatusCode.Value); }
public async Task ApplyKeywordMissing() { var mockRequest = new Mock <HttpRequest>(); var mockLogger = new Mock <ILogger>(); var mockFileWrapper = new Mock <IHelpers>(); var assembly = Assembly.LoadFrom("CalculatorFunction"); mockFileWrapper.Setup(m => m.LoadInstructionsfromFile(assembly, "CalculatorFunction.Instructions.txt")).Returns("add 10\r\nmultiply 2\r\nsubtract 5\r\nadd 2"); var function = new CalculatorFunction.CalculatorFunction(mockFileWrapper.Object); var result = await function.Calculator(mockRequest.Object, mockLogger.Object); var objectResult = result as ObjectResult; Xunit.Assert.Equal(400, objectResult?.StatusCode.Value); }
public async Task ResultAsExpected() { var mockRequest = new Mock <HttpRequest>(); var mockLogger = new Mock <ILogger>(); var mockFileWrapper = new Mock <IHelpers>(); var assembly = Assembly.LoadFrom("CalculatorFunction"); mockFileWrapper.Setup(m => m.LoadInstructionsfromFile(assembly, "CalculatorFunction.Instructions.txt")).Returns("add 2\r\nmultiply 3\r\napply 3"); var function = new CalculatorFunction.CalculatorFunction(mockFileWrapper.Object); var result = await function.Calculator(mockRequest.Object, mockLogger.Object); var request = new CalculatorResponse { Result = 15 }; var objectResult = result as ObjectResult; var value = objectResult.Value as CalculatorResponse; Xunit.Assert.Equal(value.Result, request.Result); }