예제 #1
0
        public void SetUp()
        {
            _user1 = new User
            {
                Id         = 1,
                UserName   = "******",
                FirstName  = "John",
                LastName   = "Doe",
                Active     = true,
                CreatedBy  = "Developer",
                CreatedOn  = new DateTime(2016, 01, 01),
                ModifiedBy = "Developer",
                ModifiedOn = new DateTime(2016, 01, 01)
            };
            _user2 = new User
            {
                Id         = 2,
                UserName   = "******",
                FirstName  = "John",
                LastName   = "Doe",
                Active     = true,
                CreatedBy  = "Developer",
                CreatedOn  = new DateTime(2016, 01, 02),
                ModifiedBy = "Developer",
                ModifiedOn = new DateTime(2016, 01, 02),
                Roles      = new List <Role>
                {
                    new Role {
                        Id = 1, Name = "Developer"
                    }
                }
            };
            _user3 = new User
            {
                Id         = 3,
                UserName   = "******",
                FirstName  = "Eric",
                LastName   = "Newton",
                Active     = false,
                CreatedBy  = "Developer",
                CreatedOn  = new DateTime(2016, 01, 02),
                ModifiedBy = "Developer",
                ModifiedOn = new DateTime(2016, 01, 02)
            };
            _users = new List <User>
            {
                _user1,
                _user2,
                _user3
            }.AsQueryable();

            var mockSet        = NSubstituteHelper.CreateMockDbSet(_users);
            var mockRepository = Substitute.For <IRepository <User> >();

            mockRepository.Entities.Returns(mockSet);
            _userRepository = mockRepository;
        }
        public void RollAThrowTest(List <int> diceResults, int expectedResult)
        {
            var rkLogic = new RkLogic(roll: 4, keep: 2, addToResult: 0);

            rkLogic.Random = Substitute.ForPartsOf <Random>();
            NSubstituteHelper.SubstituteMethodForResult(rkLogic.Random, x => x.Next(DiceConstants.DiceMinimum, DiceConstants.DiceMaximumForRandom), diceResults);
            var result = rkLogic.RollAThrow();

            Assert.That(result, Is.EqualTo(expectedResult));
        }
예제 #3
0
        public void GetSettingById_InvalidId_ReturnNull()
        {
            var mockSet        = NSubstituteHelper.CreateMockDbSet(_settings);
            var mockRepository = Substitute.For <IRepository <Setting> >();

            mockRepository.Entities.Returns(mockSet);

            _settingRepository = mockRepository;

            var sut     = new SettingService(_cacheService, _settingRepository);
            var setting = sut.GetSettingById(100);

            Assert.IsNull(setting);
        }
예제 #4
0
        public void SetUp()
        {
            var user1 = new User
            {
                Id         = 1,
                UserName   = "******",
                FirstName  = "John",
                LastName   = "Doe",
                Active     = true,
                CreatedBy  = "Developer",
                CreatedOn  = new DateTime(2016, 01, 01),
                ModifiedBy = "Developer",
                ModifiedOn = new DateTime(2016, 01, 01)
            };

            _role1 = new Role
            {
                Id    = 1,
                Name  = "role1",
                Users = new List <User> {
                    user1
                }
            };
            _role2 = new Role
            {
                Id   = 2,
                Name = "role2"
            };
            _role3 = new Role
            {
                Id    = 3,
                Name  = "role3",
                Users = new List <User> {
                    user1
                }
            };
            _roles = new List <Role>
            {
                _role1,
                _role2,
                _role3
            }.AsQueryable();

            var mockSet        = NSubstituteHelper.CreateMockDbSet(_roles);
            var mockRepository = Substitute.For <IRepository <Role> >();

            mockRepository.Entities.Returns(mockSet);
            _roleRepository = mockRepository;
        }
예제 #5
0
        public void SetUp()
        {
            _log1 = new Log
            {
                Id        = 1,
                Date      = new DateTime(2016, 01, 01),
                Username  = "******",
                Thread    = "1",
                Level     = "INFO",
                Logger    = "MyApp.Web.Global",
                Message   = "Demo Message 1",
                Exception = ""
            };
            _log2 = new Log
            {
                Id        = 2,
                Date      = new DateTime(2016, 01, 01),
                Username  = "******",
                Thread    = "1",
                Level     = "DEBUG",
                Logger    = "MyApp.Web.Global",
                Message   = "Demo Message 2",
                Exception = ""
            };
            _log3 = new Log
            {
                Id        = 3,
                Date      = new DateTime(2016, 01, 01),
                Username  = "******",
                Thread    = "3",
                Level     = "ERROR",
                Logger    = "MyApp.Web.Global",
                Message   = "Demo Message 3",
                Exception = ""
            };
            _logs = new List <Log>
            {
                _log1,
                _log2,
                _log3
            }.AsQueryable();

            var mockSet        = NSubstituteHelper.CreateMockDbSet(_logs);
            var mockRepository = Substitute.For <IRepository <Log> >();

            mockRepository.Entities.Returns(mockSet);
            _logRepository = mockRepository;
        }
예제 #6
0
        public async Task UpdateUser_CallAddOrUpdateFromDbSetAndCallSaveChangesAsync()
        {
            // Arrange
            var mockSet        = NSubstituteHelper.CreateMockDbSet <User>();
            var mockRepository = Substitute.For <IRepository <User> >();

            mockRepository.Entities.Returns(mockSet);
            var service = new UserService(mockRepository);

            // Act
            await service.UpdateUserAsync(_user1);

            // Assert
            mockSet.Received(1).AddOrUpdate(Arg.Any <User>());
            await mockRepository.Received(1).SaveChangesAsync();
        }
예제 #7
0
        public void SetUp()
        {
            _setting1 = new Setting
            {
                Id    = 1,
                Name  = "text",
                Value = "Alpha Bravo Charlie"
            };
            _setting2 = new Setting
            {
                Id    = 2,
                Name  = "boolean",
                Value = "true"
            };
            _setting3 = new Setting
            {
                Id    = 3,
                Name  = "integer",
                Value = "123"
            };
            _setting4 = new Setting
            {
                Id    = 4,
                Name  = "decimal",
                Value = "12.34"
            };
            _settings = new List <Setting>
            {
                _setting1,
                _setting2,
                _setting3,
                _setting4,
            }.AsQueryable();

            _cacheService = new NullCache();

            var mockSet        = NSubstituteHelper.CreateMockDbSet(_settings);
            var mockRepository = Substitute.For <IRepository <Setting> >();

            mockRepository.Entities.Returns(mockSet);
            _settingRepository = mockRepository;
        }
예제 #8
0
        public void SetUp()
        {
            _traceLog1 = new TraceLog
            {
                Id          = 1,
                Controller  = "Logs",
                Action      = "List",
                Message     = "{\"request\":{\"Page\":1,\"PageSize\":10,\"Sorts\":[],\"Filters\":[]}}",
                PerformedOn = new DateTime(2016, 01, 01),
                PerformedBy = "johndoe",
            };
            _traceLog2 = new TraceLog
            {
                Id          = 2,
                Controller  = "TraceLog",
                Action      = "Index",
                Message     = "{}",
                PerformedOn = new DateTime(2016, 01, 01),
                PerformedBy = "johndoe",
            };
            _traceLog3 = new TraceLog
            {
                Id          = 1,
                Controller  = "Logs",
                Action      = "List",
                Message     = "{\"request\":{\"Page\":1,\"PageSize\":10,\"Sorts\":[],\"Filters\":[]}}",
                PerformedOn = new DateTime(2016, 01, 01),
                PerformedBy = "janetdoe",
            };
            _traceLogs = new List <TraceLog>
            {
                _traceLog1,
                _traceLog2,
                _traceLog3
            }.AsQueryable();

            var mockSet        = NSubstituteHelper.CreateMockDbSet(_traceLogs);
            var mockRepository = Substitute.For <IRepository <TraceLog> >();

            mockRepository.Entities.Returns(mockSet);
            _traceLogRepository = mockRepository;
        }