public void ReturnEmptySetGivenEmptyString()
        {
            var str       = "";
            var converter = new ConnectionIdsConverter();

            var result = converter.ToEntityAttribute(str);

            Assert.Equal(new HashSet <string>(), result);
        }
        public void ReturnEmptyStringGivenEmptySet()
        {
            var set       = new HashSet <string>();
            var converter = new ConnectionIdsConverter();

            var result = converter.ToDbColumn(set);

            Assert.Equal("", result);
        }
        public void ReturnSetWithMultipleValuesGivenStringWithMultipleValuesSeparated()
        {
            var str       = "test1;test2";
            var converter = new ConnectionIdsConverter();

            var result = converter.ToEntityAttribute(str);

            Assert.Equal(new HashSet <string> {
                "test1", "test2"
            }, result);
        }
        public void ReturnSingletonSetGivenStringWithoutSeparators()
        {
            var str       = "test";
            var converter = new ConnectionIdsConverter();

            var result = converter.ToEntityAttribute(str);

            Assert.Equal(new HashSet <string> {
                "test"
            }, result);
        }
        public void ReturnSeparatedValuesGivenSetWithMultipleValues()
        {
            var set = new HashSet <string>()
            {
                "test1", "test2"
            };
            var converter = new ConnectionIdsConverter();

            var result = converter.ToDbColumn(set);

            Assert.Equal("test1;test2", result);
        }
        public void ReturnStringWithoutSeparatorGivenSingletonSet()
        {
            var set = new HashSet <string>()
            {
                "test"
            };
            var converter = new ConnectionIdsConverter();

            var result = converter.ToDbColumn(set);

            Assert.Equal("test", result);
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity <UserParticipationInLobby>()
            .HasKey(participation => new { participation.LobbyID, participation.UserID });
            modelBuilder.Entity <UserParticipationInLobby>()
            .HasOne(participation => participation.Lobby)
            .WithMany(lobby => lobby.UserParticipations);
            modelBuilder.Entity <UserParticipationInLobby>()
            .HasOne(participation => participation.User)
            .WithOne(user => user.LobbyParticipation)
            .HasForeignKey <UserParticipationInLobby>(participation => participation.UserID);

            // hub connections of the user are hold in db as a string
            var converter = new ConnectionIdsConverter();

            modelBuilder.Entity <UserParticipationInLobby>()
            .Property(p => p.ConnectionIds)
            .HasConversion(
                connectionIds => converter.ToDbColumn(connectionIds),
                connectionIdsStrings => converter.ToEntityAttribute(connectionIdsStrings)
                );

            var testUser = new User()
            {
                Id       = "testuserid",
                Email    = "*****@*****.**",
                UserName = "******"
            };
            var testParticipation = new UserParticipationInLobby()
            {
                LobbyID = 5,
                UserID  = testUser.Id
            };
            var testLobby = new Lobby()
            {
                ID      = 5,
                Name    = "POKÓJ TESTOWY",
                Private = false,
                OwnerID = testUser.Id,
            };

            modelBuilder.Entity <User>().HasData(testUser);

            modelBuilder.Entity <Lobby>().HasData(testLobby);

            modelBuilder.Entity <UserParticipationInLobby>().HasData(testParticipation);
        }