示例#1
0
        public ComponentTestGenerator(ComponentTestDTO dataTransferObject, string clsName)
        {
            dto       = dataTransferObject;
            className = clsName;

            componentTestTemplate  = new CodeCompileUnit();
            componentTestNamespace = new CodeNamespace("AutoGeneratedTests");

            //Add namespace imports to the class.
            componentTestNamespace.Imports.Add(new CodeNamespaceImport("System"));
            componentTestNamespace.Imports.Add(new CodeNamespaceImport("System.Net"));
            componentTestNamespace.Imports.Add(new CodeNamespaceImport("Newtonsoft.Json"));
            componentTestNamespace.Imports.Add(new CodeNamespaceImport("System.Threading.Tasks"));
            componentTestNamespace.Imports.Add(new CodeNamespaceImport("Microsoft.VisualStudio.TestTools.UnitTesting"));
            componentTestTemplate.Namespaces.Add(componentTestNamespace);

            // Declare the class and make it public.
            componentTestClass                = new CodeTypeDeclaration();
            componentTestClass.Name           = dto.DTOName + "UnitTests";
            componentTestClass.IsClass        = true;
            componentTestClass.TypeAttributes = System.Reflection.TypeAttributes.Public;

            // Add type class for this test suite to an object that will handle complex types for our test suite.
            complexUnitTestGenerator = new ComplexTypeComponentTestGenerator(componentTestClass, dto);

            GenerateUnitTests();
        }
        public ActionResult ReadDTO(ComponentTestDTO dto)
        {
            DTOGenerator           dtoTemplate            = new DTOGenerator(dto, dto.DTOName + ".cs");
            ComponentTestGenerator componentTestsTemplate = new ComponentTestGenerator(dto, dto.DTOName + "Tests.cs");

            string path = System.Web.Hosting.HostingEnvironment.MapPath(@"~/Generated");

            System.IO.DirectoryInfo dirInfo = new DirectoryInfo(path);
            foreach (FileInfo file in dirInfo.GetFiles())
            {
                if (file.Extension.Equals(".cs"))
                {
                    file.Delete();
                }
            }

            // Generate the code for the client.
            dtoTemplate.GenerateCSharpCode();
            componentTestsTemplate.GenerateCSharpCode();

            // If the directory for storing generated code doesn't exist yet, create it.
            string pathForZips = System.Web.Hosting.HostingEnvironment.MapPath(@"~/GeneratedCode");

            if (!Directory.Exists(pathForZips))
            {
                Directory.CreateDirectory(pathForZips);
            }

            string path2 = pathForZips + @"/" + dto.DTOName + "Archive";

            System.IO.DirectoryInfo dirInfo2 = new DirectoryInfo(pathForZips);

            // Get rid of old archives since they are no longer needed.
            foreach (FileInfo file in dirInfo2.GetFiles())
            {
                if (file.Extension.Equals(".zip"))
                {
                    file.Delete();
                }
            }

            // Creates the archive to send to the client.
            ZipFile.CreateFromDirectory(path, path2 + ".zip");

            // Clear the response header and then send the zip to the client.
            Response.Clear();
            Response.AddHeader("Content-Disposition", "attatchment;filename=\"" + dto.DTOName + "Archive.zip\"");
            Response.WriteFile(path2 + ".zip");


            return(Content("Success"));
        }
示例#3
0
 public ComplexTypeComponentTestGenerator(CodeTypeDeclaration componentTestClass, ComponentTestDTO dataTransferObject)
 {
     testSuite = componentTestClass;
     dto       = dataTransferObject;
 }
        public void TestMethodNull()
        {
            ComponentTestDTO dto = new ComponentTestDTO();

            Assert.IsNotNull(dto);
        }
        public ActionResult Main()
        {
            ComponentTestDTO dto = new ComponentTestDTO();

            return(View(dto));
        }