Example #1
0
        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);
            }
        }
Example #2
0
        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);
            }
        }
Example #3
0
        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);
            }
        }
Example #4
0
 public void ConstructorNullAppEnvironmentTest()
 {
     try
     {
         // Arrange
         // Act
         var webApplicationAssemblyStorage =
             new utes.WebApplicationAssemblyStorage.WebApplicationAssemblyStorage(null, null);
     }
     catch (ArgumentNullException argumentNullException)
     {
         // Assert
         Assert.NotNull(argumentNullException);
         Assert.Equal("appEnvironment", argumentNullException.ParamName);
     }
 }
Example #5
0
        public void GetClassesInAssemblyTest()
        {
            // Arrange
            var hostingEnvironmentMock = new Mock <IHostingEnvironment>();

            hostingEnvironmentMock.Setup(x => x.ContentRootPath).Returns(TestDllDirectory);

            var webApplicationAssemblyStorage = new utes.WebApplicationAssemblyStorage.WebApplicationAssemblyStorage(
                hostingEnvironmentMock.Object, new[] { new JsonDataSourceAttribute() });

            // Act
            var assemblyClasses = webApplicationAssemblyStorage.GetClassesInAssembly(CoreTestsAssemblyName);

            // Assert
            Assert.NotNull(assemblyClasses);
            Assert.NotEmpty(assemblyClasses);
        }
Example #6
0
        public void ConstructorNullMethodAttributesTest()
        {
            try
            {
                // Arrange
                var hostingEnvironmentMock = new Mock <IHostingEnvironment>();

                // Act
                var webApplicationAssemblyStorage =
                    new utes.WebApplicationAssemblyStorage.WebApplicationAssemblyStorage(hostingEnvironmentMock.Object,
                                                                                         null);
            }
            catch (ArgumentNullException argumentNullException)
            {
                // Assert
                Assert.NotNull(argumentNullException);
                Assert.Equal("methodAttributes", argumentNullException.ParamName);
            }
        }
Example #7
0
        public void GetMethodsInClassTest()
        {
            // Arrange
            var hostingEnvironmentMock = new Mock <IHostingEnvironment>();

            hostingEnvironmentMock.Setup(x => x.ContentRootPath).Returns(TestDllDirectory);

            var webApplicationAssemblyStorage = new utes.WebApplicationAssemblyStorage.WebApplicationAssemblyStorage(
                hostingEnvironmentMock.Object, new[] { new JsonDataSourceAttribute() });

            // Act
            var classMethods = webApplicationAssemblyStorage.GetMethodsInClass(new Class
            {
                Name         = "JsonDataSource",
                AssemblyName = CoreTestsAssemblyName
            });

            // Assert
            Assert.NotNull(classMethods);
            Assert.NotEmpty(classMethods);
        }
Example #8
0
        public void ConstructorTest()
        {
            try
            {
                // Arrange
                var hostingEnvironmentMock = new Mock <IHostingEnvironment>();
                hostingEnvironmentMock.Setup(x => x.ContentRootPath).Returns(NonExistentTestDllDirectory);

                var methodAttributeMock = new Mock <IMethodAttribute>();

                // Act
                var webApplicationAssemblyStorage = new utes.WebApplicationAssemblyStorage.WebApplicationAssemblyStorage
                                                    (
                    hostingEnvironmentMock.Object, new[] { methodAttributeMock.Object });
            }
            catch (ArgumentNullException argumentNullException)
            {
                // Assert
                Assert.NotNull(argumentNullException);
                Assert.Equal("Value cannot be null.\r\nParameter name: methodAttributes", argumentNullException.Message);
            }
        }
Example #9
0
        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);
        }
Example #10
0
        public void GetAssembliesTest()
        {
            // Arrange
            var hostingEnvironmentMock = new Mock <IHostingEnvironment>();

            hostingEnvironmentMock.Setup(x => x.ContentRootPath).Returns(TestDllDirectory);

            var methodAttributeMock = new Mock <IMethodAttribute>();

            var webApplicationAssemblyStorage = new utes.WebApplicationAssemblyStorage.WebApplicationAssemblyStorage(
                hostingEnvironmentMock.Object, new[] { methodAttributeMock.Object });

            // Act
            var assemblies = webApplicationAssemblyStorage.GetAssemblies();

            // Assert
            Assert.NotNull(assemblies);

            var assembliesArray = assemblies.ToArray();

            Assert.NotEmpty(assembliesArray);
            Assert.Equal(2, assembliesArray.Length);

            var assembly = assembliesArray[0];

            Assert.Null(assembly.ContentBytes);
            Assert.NotNull(assembly.Version);
            Assert.Equal(CoreTestsAssemblyName, assembly.Name);
            Assert.Equal(Path.Combine(DllDirectory, CoreTestsAssemblyNameWithExtension), assembly.Path);

            assembly = assembliesArray[1];
            Assert.Null(assembly.ContentBytes);
            Assert.NotNull(assembly.Version);
            Assert.Equal(AssemblyName, assembly.Name);
            Assert.Equal(Path.Combine(DllDirectory, AssemblyNameWithExtension), assembly.Path);
        }