public void GetLectureByExternalId_ReturnsNull_WhenLectureDoesntExist()
        {
            // Arrange
            List <Lecture> testLectures = new List <Lecture>
            {
                new Lecture {
                    ExternalId = 1, Id = 3123, Title = "Lecture 1"
                },
                new Lecture {
                    ExternalId = 2, Id = 4324, Title = "Lecture 2"
                }
            };

            IRepository <Lecture> repository = new RepositoryMock <Lecture>();

            testLectures.ForEach(lecture => repository.Add(lecture));

            ILecturesService service = SetupLecturesService(repository);

            int lectureId = 6;

            // Act
            Lecture returnedLecture = service.GetLectureByExternalId(lectureId);

            // Assert
            Assert.IsNull(returnedLecture);
        }
Exemplo n.º 2
0
        //
        //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()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Add
        ///</summary>
        public void AddTestHelper <T>()
            where T : class
        {
            RepositoryMock <T> target = new RepositoryMock <T>(); // TODO: Initialize to an appropriate value
            T EntityObject            = null;                     // TODO: Initialize to an appropriate value

            target.Add(EntityObject);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Exemplo n.º 3
0
        public void Save_Will_Call_NotifyItemWasChanged()
        {
            var story = new Story {
                Id = 42
            };
            var model = new EditStoryModel {
                Id = 42
            };

            repository.Add(story);
            controller.Save(model);
            Assert.That(repository.NotifyItemWasChangedLastCalledWith, Is.EqualTo(story));
        }
        public void Init()
        {
            this.autoMapperConfig = new AutoMapperConfig();
            this.autoMapperConfig.Execute(Assembly.Load("ForumApp.Mvc"));

            var repo = new RepositoryMock <Forum>();

            for (int i = 0; i < DataCount; i++)
            {
                repo.Add(new Forum()
                {
                    Id = i, Title = "Title" + i
                });
            }

            this.controller = new HomeController(new ForumService(repo, new CacheServiceMock()));
        }
Exemplo n.º 5
0
        public void Init()
        {
            this.autoMapperConfig = new AutoMapperConfig();
            this.autoMapperConfig.Execute(Assembly.Load("ForumApp.Mvc"));

            var repo = new RepositoryMock <Comment>();

            for (int i = 0; i < DataCount; i++)
            {
                repo.Add(new Comment()
                {
                    Id = i, Text = "Text" + i, PostId = 1
                });
            }

            var repo2 = new RepositoryMock <Post>();

            for (int i = 0; i < DataCount; i++)
            {
                repo2.Add(new Post()
                {
                    Id = i, Text = "Text" + i
                });
            }

            this.controller = new PostController(
                new CommentService(repo, new CacheServiceMock()),
                new PostService(repo2, new CacheServiceMock()));

            var context = new Mock <ControllerContext>();
            var session = new Mock <HttpSessionStateBase>();

            session.Setup(s => s["postId"]).Returns(1);
            context.Setup(m => m.HttpContext.Session).Returns(session.Object);
            this.controller.ControllerContext = context.Object;
        }
Exemplo n.º 6
0
        public void GetCustomerStatisticsExceptionTest()
        {
            IRepository <Measurement> measurerepo = new RepositoryMock <Measurement>();

            DateTime StartDate = DateTime.Now.Subtract(TimeSpan.FromDays(1000));;
            DateTime EndDate   = StartDate.AddDays(100);
            Customer customer  = new Customer()
            {
                Person = new Person()
                {
                    Email     = "*****@*****.**",
                    Firstname = "PersonVorname",
                    Lastname  = "PersonNachname",
                    Password  = "******",
                    Username  = "******"
                }
            };
            StatisticsService target = new StatisticsService(measurerepo);
            Site site = new Site()
            {
                Description  = "Description",
                Latitude     = 43.012312,
                Longitude    = 12.12312,
                Serialnumber = "!§$%&/()",
                SiteID       = 1
            };

            Measurement exp1 = new Measurement()
            {
                MeasurementID = 2,
                Time          = StartDate.AddDays(11),
                Value         = 100,
                Site          = site
            };

            Measurement exp2 = new Measurement()
            {
                MeasurementID = 4,
                Time          = StartDate.AddDays(25),
                Value         = 100,
                Site          = site
            };



            Measurement somemeasure1 = new Measurement()
            {
                MeasurementID = 1,
                Time          = StartDate.Subtract(TimeSpan.FromDays(1)),
                Value         = 100,
                Site          = site
            };

            site.Measurements.Add(somemeasure1);

            Measurement somemeasure2 = new Measurement()
            {
                MeasurementID = 3,
                Time          = EndDate.AddDays(1),
                Value         = 100,
                Site          = site
            };

            site.Measurements.Add(somemeasure2);
            site.Customer = customer;

            customer.Sites.Add(site);

            measurerepo.Add(somemeasure1);
            measurerepo.Add(somemeasure2);
            measurerepo.Add(exp1);
            measurerepo.Add(exp2);
            List <Measurement> expected = new List <Measurement>()
            {
                exp1, exp2
            };
            List <Measurement> actual;

            actual = target.GetCustomerStatistics(customer, StartDate, EndDate);
            CollectionAssert.AreEqual(actual, expected);
        }
Exemplo n.º 7
0
        public void GetCustomerStatisticsExceptionTest()
        {
            IRepository<Measurement> measurerepo = new RepositoryMock<Measurement>();
            
            DateTime StartDate = DateTime.Now.Subtract(TimeSpan.FromDays(1000)); ;
            DateTime EndDate = StartDate.AddDays(100);
            Customer customer = new Customer()
            {
                Person = new Person()
                {
                    Email = "*****@*****.**",
                    Firstname = "PersonVorname",
                    Lastname = "PersonNachname",
                    Password = "******",
                    Username = "******"
                }
            };
            StatisticsService target = new StatisticsService(measurerepo);
            Site site = new Site()
            {
                Description = "Description",
                Latitude = 43.012312,
                Longitude = 12.12312,
                Serialnumber = "!§$%&/()",
                SiteID = 1
            };

            Measurement exp1 = new Measurement()
            {
                MeasurementID = 2,
                Time = StartDate.AddDays(11),
                Value = 100,
                Site = site
            };

            Measurement exp2 = new Measurement()
            {
                MeasurementID = 4,
                Time = StartDate.AddDays(25),
                Value = 100,
                Site = site
            };

            
            
            Measurement somemeasure1 = new Measurement()
            {
                MeasurementID = 1,
                Time = StartDate.Subtract(TimeSpan.FromDays(1)),
                Value = 100,
                Site = site
            };
            site.Measurements.Add(somemeasure1);

            Measurement somemeasure2 = new Measurement()
            {
                MeasurementID = 3,
                Time = EndDate.AddDays(1),
                Value = 100,
                Site = site
            };

            site.Measurements.Add(somemeasure2);
            site.Customer = customer;

            customer.Sites.Add(site);

            measurerepo.Add(somemeasure1);
            measurerepo.Add(somemeasure2);
            measurerepo.Add(exp1);
            measurerepo.Add(exp2);
            List<Measurement> expected =  new List<Measurement>(){ exp1, exp2};
            List<Measurement> actual;
            actual = target.GetCustomerStatistics(customer, StartDate, EndDate);
            CollectionAssert.AreEqual(actual, expected);
        }