Beispiel #1
0
        public ulong ResolveAuthorId(ChatEntry chatEntry)
        {
            var userMap = fileOperationService.GetUserMap();
            var userId  = userMap.SingleOrDefault(map => map.Names.Contains(chatEntry.Author))?.Id ?? 0;

            if (userId != 0)
            {
                return(userId);
            }

            userId = userInteractionService.AskForAuthor(chatEntry.Author, userMap);
            userMap.Single(map => map.Id == userId).Names.Add(chatEntry.Author);
            fileOperationService.SetUserMap(userMap);
            return(userId);
        }
        public void SetUserMap_WithJson_ExpectJsonCorrectlyWritten()
        {
            var user1 = SmeuTestDataFactory.NewUser(3, new List <string> {
                Author1
            });
            var userMap = new List <User>()
            {
                user1
            };

            fileOperationService.SetUserMap(userMap);

            var file   = File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "/userids.json");
            var result = JsonConvert.DeserializeObject <List <User> >(file);

            result.Count.Should().Be(1);
            result.First().Id.Should().Be(user1.Id);
            result.First().Names.Count.Should().Be(1);
            result.First().Names.First().Should().Be(Author1);
        }