示例#1
0
        public async Task Setup()
        {
            var storage = new JsonStorage(new Mock <Serilog.ILogger>().Object);

            _state = new OptOutState(storage);
            await _state.Start();

            storage.DeleteFile("optouts");
            await _state.Start();
        }
示例#2
0
        public async Task RestartingStateWillContinueWhereLeftOff()
        {
            var count = _state.ChannelList.Count();

            Assert.AreEqual(0, count);

            var expected = Guid.NewGuid().ToString();
            await _state.AddUserToOptOutOfChannel(new Models.Person()
            {
                UserId = "1", UserName = expected
            }, "testroom");

            count = _state.ChannelList["testroom"].UsersThatHaveOptedOut.Count();
            Assert.AreEqual(1, count);


            var storage  = new JsonStorage(new Mock <Serilog.ILogger>().Object);
            var newState = new OptOutState(storage);

            await newState.Start();

            count = _state.ChannelList.Count();
            Assert.AreEqual(1, count);
            Assert.AreEqual(expected, _state.ChannelList["testroom"].UsersThatHaveOptedOut.Single(u => u.UserId == "1").UserName);
        }
示例#3
0
        public async Task UsersAddedCanThenBeRemoved()
        {
            var storage = new JsonStorage(new Mock <Serilog.ILogger>().Object);
            var state   = new OptOutState(storage);
            await state.Start();

            storage.DeleteFile("optouts");
            Assert.AreEqual(0, state.ChannelList.Count());

            await state.AddUserToOptOutOfChannel(new Models.Person()
            {
                UserId = "1", UserName = "******"
            }, "testroom");

            await state.AddUserToOptOutOfChannel(new Models.Person()
            {
                UserId = "2", UserName = "******"
            }, "testroom");

            var count = state.ChannelList["testroom"].UsersThatHaveOptedOut.Count();

            Assert.AreEqual(2, count);
            await state.RemoveUserFromOptOutOfChannel(new Models.Person()
            {
                UserId = "2", UserName = "******"
            }, "testroom");

            count = state.ChannelList["testroom"].UsersThatHaveOptedOut.Count();
            Assert.AreEqual(1, count);
        }