public void TestAssemblyInfoFunction(string prefix, string function, string assemblyPath, string attributeFullName) { string[] args = { assemblyPath, attributeFullName }; string fullPath = @"C:\Sample.TestLib.dll"; string assemblyTitle = "Sample.TestLib"; object assemblyInfo = new { Title = assemblyTitle }; var systemReflectionWrapper = Substitute.For<ISystemReflectionWrapper>(); var systemPathWrapper = Substitute.For<IPath>(); var systemFileWrapper = Substitute.For<IFile>(); var pathHelper = Substitute.ForPartsOf<PathHelper>(systemPathWrapper, systemFileWrapper); var reflectionHelper = Substitute.ForPartsOf<ReflectionHelper>(); var preprocessorExtension = new AssemblyInfoPreprocessorExtension(pathHelper, reflectionHelper, systemReflectionWrapper); reflectionHelper.GetAssemblyAttributeInfo(Arg.Any<string>(), Arg.Any<string>()).Returns(assemblyInfo); systemFileWrapper.Exists(assemblyPath).Returns(true); systemPathWrapper.GetFullPath(assemblyPath).Returns(fullPath); var result = preprocessorExtension.EvaluateFunction(prefix, function, args); Assert.AreEqual(result, assemblyTitle, "The attribute value has been changed during the execution!"); }
public void TestFileVersionFunction(string prefix, string function, string assemblyPath) { // Arrange string[] args = { assemblyPath }; string fullPath = @"C:\Sample.TestLib.dll"; string productName = "Sample.TestLib"; var systemReflectionWrapper = Substitute.For<ISystemReflectionWrapper>(); var systemPathWrapper = Substitute.For<IPath>(); var systemFileWrapper = Substitute.For<IFile>(); var pathHelper = Substitute.ForPartsOf<PathHelper>(systemPathWrapper, systemFileWrapper); var fileVersionInfo = Substitute.ForPartsOf<FileVersionInfoWrapper>(); var reflectionHelper = Substitute.ForPartsOf<ReflectionHelper>(); var preprocessorExtension = new AssemblyInfoPreprocessorExtension(pathHelper, reflectionHelper, systemReflectionWrapper); fileVersionInfo.ProductName = productName; systemFileWrapper.Exists(assemblyPath).Returns(true); systemPathWrapper.GetFullPath(assemblyPath).Returns(fullPath); systemReflectionWrapper.GetFileVersionInfo(fullPath).Returns(fileVersionInfo); // Act var result = preprocessorExtension.EvaluateFunction(prefix, function, args); // Assert Assert.AreEqual(result, productName, "Wrong product name!"); }
public void TestWrongPrefix(string prefix, string function, string assemblyPath) { // Arrange string fullPath; string[] args = { assemblyPath }; var systemReflectionWrapper = Substitute.For<ISystemReflectionWrapper>(); var pathHelper = Substitute.For<IPathHelper>(); var reflectionHelper = Substitute.For<IReflectionHelper>(); var preprocessorExtension = new AssemblyInfoPreprocessorExtension(pathHelper, reflectionHelper, systemReflectionWrapper); // Act var result = preprocessorExtension.EvaluateFunction(prefix, function, args); // Assert pathHelper.DidNotReceiveWithAnyArgs().TryPath(Arg.Any<string>(), out fullPath); systemReflectionWrapper.DidNotReceiveWithAnyArgs().GetFileVersionInfo(Arg.Any<string>()); reflectionHelper.DidNotReceiveWithAnyArgs().GetPropertyValueByName(Arg.Any<object>(), Arg.Any<string>()); Assert.IsNull(result, "The prefix somehow got processed"); }
public void TestFileVersionFunction_Exception_WrongAttribute(string prefix, string function, string assemblyPath) { // Arrange string[] args = { assemblyPath }; string fullPath = @"C:\Sample.TestLib.dll"; var systemReflectionWrapper = Substitute.For<ISystemReflectionWrapper>(); var systemPathWrapper = Substitute.For<IPath>(); var systemFileWrapper = Substitute.For<IFile>(); var pathHelper = Substitute.ForPartsOf<PathHelper>(systemPathWrapper, systemFileWrapper); var fileVersionInfo = Substitute.ForPartsOf<FileVersionInfoWrapper>(); var reflectionHelper = Substitute.ForPartsOf<ReflectionHelper>(); var preprocessorExtension = new AssemblyInfoPreprocessorExtension(pathHelper, reflectionHelper, systemReflectionWrapper); systemFileWrapper.Exists(assemblyPath).Returns(true); systemPathWrapper.GetFullPath(assemblyPath).Returns(fullPath); systemReflectionWrapper.GetFileVersionInfo(fullPath).Returns(fileVersionInfo); // Act // Assert Assert.Throws<InvalidOperationException>(() => preprocessorExtension.EvaluateFunction(prefix, function, args), "An incorrect attribute got processed!"); systemPathWrapper.Received().IsPathRooted(assemblyPath); }
public void TestFileVersionFunction_Exception_EmptyPath(string prefix, string function, string assemblyPath) { string[] args = { assemblyPath }; var systemReflectionWrapper = Substitute.For<ISystemReflectionWrapper>(); var systemPathWrapper = Substitute.For<IPath>(); var systemFileWrapper = Substitute.For<IFile>(); var pathHelper = Substitute.ForPartsOf<PathHelper>(systemPathWrapper, systemFileWrapper); var reflectionHelper = Substitute.For<IReflectionHelper>(); var preprocessorExtension = new AssemblyInfoPreprocessorExtension(pathHelper, reflectionHelper, systemReflectionWrapper); systemFileWrapper.Exists(assemblyPath).Returns(false); systemPathWrapper.DidNotReceiveWithAnyArgs().GetFullPath(Arg.Any<string>()); systemPathWrapper.DidNotReceiveWithAnyArgs().IsPathRooted(Arg.Any<string>()); systemReflectionWrapper.DidNotReceiveWithAnyArgs().GetFileVersionInfo(Arg.Any<string>()); var ex = Assert.Throws<ArgumentNullException>(() => preprocessorExtension.EvaluateFunction(prefix, function, args), "The path was processed!"); Assert.That(ex.Message, Is.StringContaining("The file path has not been specified!"), "Exception thrown by another argument!"); }