public void BodyParameterReqestedThenReadFile() { FileMailTemplate reader = new FileMailTemplate(_fileSystem) { Name = _templateName, Path = _correctPath }; string result = reader.Body; Assert.Equal(_fileContent, result); Mock.Get(_fileSystem).Verify(f => f.File.ReadAllText(_correctPath), Times.Once); }
public Class() { Mock.Get(_fileSystem).Setup(f => f.File.Exists(_correctPath)).Returns(true); Mock.Get(_fileSystem).Setup(f => f.File.ReadAllText(_correctPath)).Returns(_fileContent); Mock.Get(_fileSystem) .Setup(f => f.Path.Combine(It.IsAny <string>(), It.IsAny <string>())) .Returns((string a, string b) => { return(Path.Combine(a, b)); }); Mock.Get(_fileSystem) .Setup(f => f.Path.Combine(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns((string a, string b, string c) => { return(Path.Combine(a, b, c)); }); Mock.Get(_fileSystem) .Setup(f => f.Path.Combine(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns((string a, string b, string c) => { return(Path.Combine(a, b, c)); }); _template = new FileMailTemplate(_fileSystem); }
public void StoreInMemoryEnabledThenReadFileOnce() { FileMailTemplate reader = new FileMailTemplate(_fileSystem) { Name = _templateName, Path = _correctPath, StoreInMemory = true }; for (int i = 0; i < 10; i++) { string result = reader.Body; Assert.Equal(_fileContent, result); } Mock.Get(_fileSystem).Verify(f => f.File.ReadAllText(_correctPath), Times.Once); }
public void StoreInMemoryDisabledThenReadFileAtRead() { FileMailTemplate reader = new FileMailTemplate(_fileSystem) { Name = _templateName, Path = _correctPath, StoreInMemory = false }; int readCount = 10; for (int i = 0; i < readCount; i++) { string result = reader.Body; Assert.Equal(_fileContent, result); } Mock.Get(_fileSystem).Verify(f => f.File.ReadAllText(_correctPath), Times.Exactly(readCount)); }
public void AfterCreationFileUnableReadThenNullBodyReturned() { string path = "new path"; string content = "new content"; Mock.Get(_fileSystem).Setup(f => f.File.Exists(path)).Returns(true); Mock.Get(_fileSystem).Setup(f => f.File.ReadAllText(_correctPath)).Returns(content); Mock.Get(_fileSystem).Setup(f => f.File.Exists(path)).Returns(true); Mock.Get(_fileSystem).Setup(f => f.File.ReadAllText(_correctPath)).Throws(new Exception()); FileMailTemplate reader = new FileMailTemplate(_fileSystem) { Name = _templateName, Path = _correctPath }; string result = reader.Body; Assert.Null(result); }
public void ItExists() { FileMailTemplate reader = new FileMailTemplate(); }