public static void GetById(IUnityContainer container, CoolThing result)
        {
            var coolRepositoryMock = container.Resolve <Mock <ICoolRepository> >();

            coolRepositoryMock
            .Setup(x => x.Get(It.IsAny <int>()))
            .Returns(result);
        }
        public void Return_Cool_Thing_Is_Not_Really_Cool_For_Even_Id_Cool_Thing()
        {
            var coolThing = new CoolThing
            {
                Id = 14
            };

            var awesomeService = ServicesCreator.AwesomeService(UnitTestContext.Instance.Container);
            var isItReallyCool = awesomeService.IsItReallyCool(coolThing);

            Assert.That(
                isItReallyCool,
                Is.False,
                "Non cool thing is being classified as cool");
        }
        public void Return_Cool_Thing_Is_Really_Cool_For_Odd_Id_Cool_Thing()
        {
            var coolThing = new CoolThing
            {
                Id = 13
            };

            var awesomeService = ServicesCreator.AwesomeService(UnitTestContext.Instance.Container);
            var isItReallyCool = awesomeService.IsItReallyCool(coolThing);

            Assert.That(
                isItReallyCool,
                Is.True,
                "Actual cool thing is being classified as non cool");
        }
        public void Raise_Exception_For_Non_Cool_Thing()
        {
            const int id        = 14;
            var       coolThing = new CoolThing
            {
                Id = id
            };

            CoolRepositoryMocks.GetById(UnitTestContext.Instance.Container, coolThing);
            AwesomeServiceMocks.IsItReallyCool(UnitTestContext.Instance.Container, false);

            var amazingService = ServicesCreator.AmazingService(UnitTestContext.Instance.Container);

            Assert.Throws <Exception>(
                () => amazingService.GetById(id),
                "No exception is raised for non cool thing");
        }
        public void Successfully_Retrieve_Exisiting_Cool_Thing()
        {
            const int id        = 13;
            var       coolThing = new CoolThing
            {
                Id = id
            };

            CoolRepositoryMocks.GetById(UnitTestContext.Instance.Container, id, coolThing);
            AwesomeServiceMocks.IsItReallyCool(UnitTestContext.Instance.Container, true);

            var amazingService    = ServicesCreator.AmazingService(UnitTestContext.Instance.Container);
            var retrievedInstance = amazingService.GetById(id);

            Assert.That(
                retrievedInstance.Id,
                Is.EqualTo(coolThing.Id),
                "The cool thing is not being correctly retrieved");
        }
        public void Retrieve_Exisiting_Cool_Thing()
        {
            const int id = 13;
            var       existingCoolThing = new CoolThing
            {
                Id = id
            };

            var coolThings = new List <CoolThing> {
                existingCoolThing
            }.AsQueryable();

            CoolDbContextMocks.CoolThings(UnitTestContext.Instance.Container, coolThings);

            var coolRepository     = RepositoriesCreator.CoolRepository(UnitTestContext.Instance.Container);
            var retrievedCoolThing = coolRepository.Get(id);

            Assert.That(
                retrievedCoolThing.Id,
                Is.EqualTo(existingCoolThing.Id),
                "The retrieved cool thing is not correct");
        }
Example #7
0
 public bool IsItReallyCool(CoolThing coolThing)
 {
     /* Everyone knows that only odd numbers can be cool */
     return(coolThing != null && coolThing.Id % 2 == 1);
 }