Anonymous avatar Anonymous committed e824a0c

adding a postlogic unit test

Comments (0)

Files changed (1)

development/src/Tests/PostLogicTest.cs

+using qandaNET.BLL;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System;
+using qandaNET.Data;
+using System.Collections.Generic;
+using System.Linq;
+using qandaNET.CrossCutting;
+
+namespace Tests
+{
+    
+    
+    /// <summary>
+    ///This is a test class for PostLogicTest and is intended
+    ///to contain all PostLogicTest Unit Tests
+    ///</summary>
+    [TestClass()]
+    public class PostLogicTest
+    {
+        private const bool _isMock = true;
+        private ContentModelContainerMock _context;
+
+        #region Additional test attributes
+        // 
+        //You can use the following additional attributes as you write your tests:
+        //
+        //Use ClassInitialize to run code before running the first test in the class
+        //[ClassInitialize()]
+        //public static void MyClassInitialize(TestContext testContext)
+        //{
+        //}
+        //
+        //Use ClassCleanup to run code after all tests in a class have run
+        //[ClassCleanup()]
+        //public static void MyClassCleanup()
+        //{
+        //}
+        //
+
+        [TestInitialize()]
+        public void TestInitialize()
+        {
+            _context = DataContextFactory.CreateContentContext(_isMock) as ContentModelContainerMock;
+
+            var myType = new PostType() { NumericCode = (short)PostTypes.Question };
+
+            _context.PostTypes.AddObject(myType);
+
+            var mypost = new Post() { Type = myType };
+
+            _context.Posts.AddObject(mypost);
+            
+        }
+
+
+        //Use TestCleanup to run code after each test has run
+        //[TestCleanup()]
+        //public void MyTestCleanup()
+        //{
+        //}
+        //
+        #endregion
+
+
+        /// <summary>
+        ///A test for GetPostsByType
+        ///</summary>
+        [TestMethod()]
+        public void GetPostsByTypeTest()
+        {
+            PostLogic target = new PostLogic(_isMock);
+            PostTypes pt = PostTypes.Question;
+            PostType type = _context.PostTypes.FirstOrDefault(curPost => curPost.NumericCode == (short)pt);
+            IEnumerable<Post> expected = _context.Posts.Where(curPost => curPost.Type == type).Select(curPost => curPost).AsEnumerable();
+            IEnumerable<Post> actual = target.GetPostsByType(pt);
+
+            bool allMatch = false;
+
+            if (expected.Count() == actual.Count())
+            {
+                for (var index = 0; index < expected.Count(); index++)
+                {
+                    if (expected.ElementAt(index) == actual.ElementAt(index))
+                    {
+                        //so far so good
+                        allMatch = true;
+                    }
+                    else
+                    {
+                        allMatch = false; //make sure we know it failed
+                        break; //stop looping
+                    }
+                }
+            }
+            else
+            {
+                //different lengths, can't match
+            }
+            Assert.IsTrue(allMatch);
+        }
+    }
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.