public void SaveAssemblyWrongAssemblyFileExceptionTest() { try { // Arrange var hostingEnvironmentMock = new Mock <IHostingEnvironment>(); hostingEnvironmentMock.Setup(x => x.ContentRootPath).Returns(DummyDllDirectory); var methodAttributeMock = new Mock <IMethodAttribute>(); var webApplicationAssemblyStorage = new utes.WebApplicationAssemblyStorage.WebApplicationAssemblyStorage( hostingEnvironmentMock.Object, new[] { methodAttributeMock.Object }); var assembly = new Assembly { Name = "HelloWorld.dll", ContentBytes = new[] { byte.Parse("0"), byte.Parse("1") } }; // Act webApplicationAssemblyStorage.SaveAssembly(assembly); } catch (BadImageFormatException badImageFormatException) { // Assert Assert.Equal(" is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)", badImageFormatException.Message); } }
public void SaveAssemblyAssemblyDoesNotImplementInterfaceExceptionTest() { try { // Arrange var hostingEnvironmentMock = new Mock <IHostingEnvironment>(); hostingEnvironmentMock.Setup(x => x.ContentRootPath).Returns(DummyDllDirectory); var methodAttributeMock = new Mock <IMethodAttribute>(); var webApplicationAssemblyStorage = new utes.WebApplicationAssemblyStorage.WebApplicationAssemblyStorage( hostingEnvironmentMock.Object, new[] { methodAttributeMock.Object }); var dllPath = Directory.EnumerateFiles(AppContext.BaseDirectory, "*.dll").First(); var assembly = new Assembly { Name = "FooBar.dll", ContentBytes = File.ReadAllBytes(dllPath) }; // Act webApplicationAssemblyStorage.SaveAssembly(assembly); } catch (DataSourceAttributeNotFoundException dataSourceAttributeNotFoundException) { // Assert Assert.Equal("The uploaded assembly do not implement IMethodAttribute interface.", dataSourceAttributeNotFoundException.Message); } }
public void SaveAssemblyWrongAssemblyExtensionExceptionTest() { try { // Arrange var hostingEnvironmentMock = new Mock <IHostingEnvironment>(); hostingEnvironmentMock.Setup(x => x.ContentRootPath).Returns(DummyDllDirectory); var methodAttributeMock = new Mock <IMethodAttribute>(); var webApplicationAssemblyStorage = new utes.WebApplicationAssemblyStorage.WebApplicationAssemblyStorage( hostingEnvironmentMock.Object, new[] { methodAttributeMock.Object }); var assembly = new Assembly { Name = "HelloWorld.txt" }; // Act webApplicationAssemblyStorage.SaveAssembly(assembly); } catch (BadImageFormatException badImageFormatException) { // Assert Assert.Equal("Unexpected file extension.", badImageFormatException.Message); } }
public void SaveAssemblyTest() { // Arrange var hostingEnvironmentMock = new Mock <IHostingEnvironment>(); hostingEnvironmentMock.Setup(x => x.ContentRootPath).Returns(DummyDllDirectory); var webApplicationAssemblyStorage = new utes.WebApplicationAssemblyStorage.WebApplicationAssemblyStorage( hostingEnvironmentMock.Object, new[] { new JsonDataSourceAttribute() }); var dllPath = Directory.EnumerateFiles(AppContext.BaseDirectory, CoreTestsAssemblyNameWithExtension).First(); var assembly = new Assembly { Name = CoreTestsAssemblyNameWithExtension, ContentBytes = File.ReadAllBytes(dllPath) }; // Act webApplicationAssemblyStorage.SaveAssembly(assembly); // Assert // This case no exceptions. Assert.True(true); }