public void Remove_SingleAccount_Returns_Null()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Remove_SingleAccount_Returns_Null")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Kapitan Bomba"
                };
                //Act
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }
            //Assert
            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork = new UnitOfWork(context);
                var account    = unitOfWork.Account.GetByString("Bomba");
                unitOfWork.Account.Remove(account);
                unitOfWork.Complete();
                var expected = unitOfWork.Account.Find(x => x.Login == "Bomba").SingleOrDefault();
                account = unitOfWork.Account.GetByString("Bomba");
                Assert.Equal(expected, account);
                unitOfWork.Dispose();
            }
        }
示例#2
0
        public void Get_SingleAccountByQuestionKey_Returns_SameAccount()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Get_SingleAccountByQuestionKey_Returns_SameAccount")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Master Vilgefortz"
                };
                //Act
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }
            //Assert
            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork           = new UnitOfWork(context);
                var account              = unitOfWork.Account.GetByString("Vilgefortz");
                var accountByQuestionKey = unitOfWork.TrackingCode.GetByString(account.QuestionsKey);
                var exptected            = unitOfWork.Account.Find(x => x.QuestionsKey == account.QuestionsKey).SingleOrDefault();
                Assert.Equal(exptected, accountByQuestionKey);
                unitOfWork.Dispose();
            }
        }
        public void Add_AccountWithQuestionKey_Returns_AccountWithGeneratedQuestionKey()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Add_AccountWithQuestionKey_Returns_AccountWithGeneratedQuestionKey")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", QuestionsKey = "NienawidzePortali123", Name = "Geralt z Rivii"
                };
                //Act
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }
            //Assert
            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork = new UnitOfWork(context);
                var account    = unitOfWork.Account.GetByString("Geralt");
                var expected   = account.QuestionsKey;
                Assert.True(expected != "NienawidzePortali123");
                unitOfWork.Dispose();
            }
        }
        public void Get_SingleAccount_Returns_SameAccount()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Get_SingleAccount_Returns_SameAccount")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Harry Potter"
                };
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }

            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork = new UnitOfWork(context);

                //Act
                Account account = unitOfWork.Account.GetByString("Harry");

                //Assert
                Assert.Equal(context.Accounts.Find("Harry").Login, account.Login);
                Assert.Equal(context.Accounts.Find("Harry").Name, account.Name);
                unitOfWork.Dispose();
            }
        }
        public void Add_SingleAccount_Returns_SameAccount()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Add_SingleAccount_Returns_SameAccount")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Juliusz Cesar"
                };
                //Act
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }
            //Assert
            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork = new UnitOfWork(context);
                var account    = unitOfWork.Account.GetByString("Cesar");
                Assert.Equal("Cesar", account.Login);
                Assert.Equal("Juliusz Cesar", account.Name);
                unitOfWork.Dispose();
            }
        }
        public void Get_QuestionWithDomain_Return_TrueIfThereIsQuestionWithSuchDomain()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Get_QuestionWithDomain_Return_TrueIfThereIsQuestionWithSuchDomain")
                          .Options;

            //Arrage
            using (var context = new TietoFeedbackToolContext(options))
            {
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Johnny Mnemonic"
                };
                unitOfWork.Account.Add(newAccount);
                var questions = new List <Question>
                {
                    new Question {
                        AccountLogin = "******", Domain = "localhost:98765", QuestionText = "Do You like feedbacktool?", Enabled = true, HasRating = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:98764", QuestionText = "Are you free tonight?", Enabled = true, HasRating = false
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:98763", QuestionText = "Wanna go out for beer?", Enabled = true, HasRating = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12345", QuestionText = "Wanna go out for beer?", Enabled = true, HasRating = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12346", QuestionText = "Wanna go out for beer?", Enabled = true, HasRating = false
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12347", QuestionText = "Wanna go out for beer?", Enabled = true, HasRating = true
                    }
                };
                unitOfWork.Question.AddRange(questions);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }

            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork = new UnitOfWork(context);

                //Act
                var validValue1   = unitOfWork.Question.IsThereQuestionWithDomain("localhost:98765");
                var validValue2   = unitOfWork.Question.IsThereQuestionWithDomain("localhost:12347");
                var invalidValue1 = unitOfWork.Question.IsThereQuestionWithDomain("localhost:44350");
                var invalidValue2 = unitOfWork.Question.IsThereQuestionWithDomain("localhost:80000");

                //Assert
                Assert.True(validValue1);
                Assert.True(validValue2);
                Assert.False(invalidValue1);
                Assert.False(invalidValue1);
                unitOfWork.Dispose();
            }
        }
        public void Get_ListOfUserDomains_Returns_SameList()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Get_ListOfUserDomains_Returns_SameList")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var unitOfWork = new UnitOfWork(context);
                var accounts   = new List <Account>
                {
                    new Account()
                    {
                        Login = "******", Name = "Lis Puszczy"
                    },
                    new Account()
                    {
                        Login = "******", Name = "Vernon Roche"
                    }
                };
                unitOfWork.Account.AddRange(accounts);
                var questions = new List <Question>
                {
                    new Question {
                        AccountLogin = "******", Domain = "localhost:42345", QuestionText = "Do You like feedbacktool?", Enabled = true, HasRating = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:52345", QuestionText = "Are you free tonight?", Enabled = true, HasRating = false
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:62345", QuestionText = "Wanna go out for beer?", Enabled = true, HasRating = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12345", QuestionText = "Wanna go out for beer?", Enabled = true, HasRating = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12346", QuestionText = "Wanna go out for beer?", Enabled = true, HasRating = false
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12347", QuestionText = "Wanna go out for beer?", Enabled = true, HasRating = true
                    }
                };
                unitOfWork.Question.AddRange(questions);

                //Act
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }
            //Assert
            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork = new UnitOfWork(context);
                var domain     = unitOfWork.Account.GetUserDomains("Iorweth");
                Assert.NotNull(domain);
                Assert.Equal(3, domain.Count);
                unitOfWork.Dispose();
            }
        }
        public void Get_ListOfQuestionsByDomain_Returns_SameList()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Get_ListOfQuestionsByDomain_Returns_SameList")
                          .Options;

            //Arrage
            using (var context = new TietoFeedbackToolContext(options))
            {
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Johnny Mnemonic"
                };
                unitOfWork.Account.Add(newAccount);
                var questions = new List <Question>
                {
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12345", QuestionText = "Do You like feedbacktool?", Enabled = true, HasRating = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12345", QuestionText = "Are you free tonight?", Enabled = true, HasRating = false
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12345", QuestionText = "Wanna go out for beer?", Enabled = true, HasRating = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12345", QuestionText = "Wanna go out for beer?", Enabled = true, HasRating = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:32165", QuestionText = "Wanna go out for beer?", Enabled = true, HasRating = false
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:32165", QuestionText = "Wanna go out for beer?", Enabled = true, HasRating = true
                    }
                };
                unitOfWork.Question.AddRange(questions);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }

            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork = new UnitOfWork(context);

                //Act
                var validValue  = unitOfWork.Question.GetQuestionsByDomain("Johnny", "localhost:12345");
                var validValue2 = unitOfWork.Question.GetQuestionsByDomain("Johnny", "localhost:32165");


                //Assert
                Assert.NotNull(validValue);
                Assert.NotNull(validValue2);
                Assert.Equal(4, validValue.Count);
                Assert.Equal(2, validValue2.Count);
                unitOfWork.Dispose();
            }
        }
        public void TestGetQuestions()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "TestGetQuestions")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Peter Snow"
                };
                var questions = new List <Question>
                {
                    new Question {
                        AccountLogin = "******", Domain = "localhost:44350", QuestionText = "Do You like feedbacktool?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:44444", QuestionText = "Are you free tonight?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:44333", QuestionText = "Wanna go out for beer?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:44355", QuestionText = "Which one to go to the toilet?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:40000", QuestionText = "What do you think about our new functionality?", Enabled = true
                    }
                };
                unitOfWork.Question.AddRange(questions);
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var unitOfWork = new UnitOfWork(context);

                //Act
                var questionList = unitOfWork.Question.GetAll().ToList();
                var expected     = context.Question;

                //Assert
                Assert.Equal(expected, questionList);
                unitOfWork.Dispose();
            }
        }
示例#10
0
        public void Get_DummySurveyHtml_Returns_TrueIfFindSurveyHTML()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Get_DummySurveyHtml_Returns_TrueIfFindSurveyHTML")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Yennefer z Vengerbergu"
                };
                var questions = new List <Question>
                {
                    new Question {
                        AccountLogin = "******", Domain = "localhost:72345", QuestionText = "Do You like feedbacktool?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:82345", QuestionText = "Are you free tonight?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:92345", QuestionText = "Wanna go out for beer?", Enabled = true
                    }
                };
                //Act
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Question.AddRange(questions);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }
            //Assert
            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork  = new UnitOfWork(context);
                var account     = unitOfWork.Account.GetByString("Yennefer");
                var question    = unitOfWork.Question.Get(account.Questions[0].Id);
                var path_html   = @"../../../../TietoFeedbackTool/ClientApp/src/assets/surveyPuzzleTemplates/markingBar.html";
                var path_script = @"../../../../TietoFeedbackTool/ClientApp/src/assets/scripts/dummyScript.js";
                var dummyHTML   = unitOfWork.TrackingCode.GetDummySurveyHtml(path_html, question);
                var dummyScript = unitOfWork.TrackingCode.GetDummyScript(path_script, question);
                Assert.NotNull(dummyHTML);
                Assert.NotNull(dummyScript);
                Assert.Contains("btn feedback-marking-bar-button", dummyHTML);
                Assert.Contains("function checkDomain()", dummyScript);
                unitOfWork.Dispose();
            }
        }
        public void TestUpdateQuestion()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "TestUpdateQuestion")
                          .Options;

            //Arrange
            using (var context = new TietoFeedbackToolContext(options))
            {
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Sauron the cat"
                };
                Question newQuestion = new Question()
                {
                    AccountLogin = "******", QuestionText = "Do You like feedbacktool?", Enabled = true
                };
                unitOfWork.Question.Add(newQuestion);
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }

            using (var context = new TietoFeedbackToolContext(options))
            {
                var      unitOfWork = new UnitOfWork(context);
                Question survey     = new Question()
                {
                    AccountLogin = "******", QuestionText = "How happy are You today?", Enabled = false
                };

                //Act
                var account = unitOfWork.Account.GetByString("Sauron");
                unitOfWork.Question.UpdateQuestion(survey, account.Questions[0].Id);
                unitOfWork.Complete();
                var updated = account.Questions[0];

                //Assert
                Assert.False(updated.Enabled);
                Assert.Equal("Sauron", updated.AccountLogin);
                Assert.Equal("How happy are You today?", updated.QuestionText);
                unitOfWork.Dispose();
            }
        }
        public void Get_ListOfAccounts_Returns_SameListOfAccounts()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Get_ListOfAccounts_Returns_SameListOfAccounts")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var unitOfWork = new UnitOfWork(context);
                var accounts   = new List <Account>
                {
                    new Account {
                        Login = "******", Name = "My name is Jeff"
                    },
                    new Account {
                        Login = "******", Name = "My name is Lech"
                    },
                    new Account {
                        Login = "******", Name = "My name is Czech"
                    },
                    new Account {
                        Login = "******", Name = "My name is Rus"
                    }
                };

                //Act
                unitOfWork.Account.AddRange(accounts);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }

            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork = new UnitOfWork(context);

                //Act
                var accountList = unitOfWork.Account.GetAll().ToList();
                var expected    = context.Accounts;
                //Assert
                Assert.Equal(expected, accountList);
                unitOfWork.Dispose();
            }
        }
示例#13
0
        public void Get_CSSTemplate_Returns_TrueIfFindCSSTemplate()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Get_CSSTemplate_Returns_TrueIfFindCSSTemplate")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Yarpen Zigrin"
                };
                var questions = new List <Question>
                {
                    new Question {
                        AccountLogin = "******", Domain = "localhost:16345", QuestionText = "Do You like feedbacktool?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:17345", QuestionText = "Are you free tonight?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:18345", QuestionText = "Wanna go out for beer?", Enabled = true
                    }
                };
                //Act
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Question.AddRange(questions);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }
            //Assert
            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork  = new UnitOfWork(context);
                var account     = unitOfWork.Account.GetByString("Yarpen");
                var path        = @"../../../../TietoFeedbackTool/ClientApp/src/assets/surveyPuzzleTemplates/markingBar.css";
                var CSSTemplate = unitOfWork.TrackingCode.GetSurveyCSS(path);
                Assert.NotNull(CSSTemplate);
                Assert.Contains("background-image: url(../../../assets/img/exit.svg)", CSSTemplate);
                unitOfWork.Dispose();
            }
        }
示例#14
0
        public void Get_HTMLTemplate_Returns_TrueIfFindHTMLTemplate()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Get_HTMLTemplate_Returns_TrueIfFindHTMLTemplate")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Zoltan Chivay"
                };
                var questions = new List <Question>
                {
                    new Question {
                        AccountLogin = "******", Domain = "localhost:19345", QuestionText = "Do You like feedbacktool?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12445", QuestionText = "Are you free tonight?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12545", QuestionText = "Wanna go out for beer?", Enabled = true
                    }
                };
                //Act
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Question.AddRange(questions);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }
            //Assert
            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork   = new UnitOfWork(context);
                var account      = unitOfWork.Account.GetByString("Zoltan");
                var path         = @"../../../../TietoFeedbackTool/ClientApp/src/assets/surveyPuzzleTemplates/markingBar.html";
                var HTMLTemplate = unitOfWork.TrackingCode.GetSurveyHtml(account.QuestionsKey, path);
                Assert.NotNull(HTMLTemplate);
                Assert.Contains("btn feedback-marking-bar-button", HTMLTemplate);
                unitOfWork.Dispose();
            }
        }
示例#15
0
        public void Get_Script_Returns_TrueIfFinScript()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Get_Script_Returns_TrueIfFinScript")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Triss Merigold"
                };
                var questions = new List <Question>
                {
                    new Question {
                        AccountLogin = "******", Domain = "localhost:13345", QuestionText = "Do You like feedbacktool?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:14345", QuestionText = "Are you free tonight?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:15345", QuestionText = "Wanna go out for beer?", Enabled = true
                    }
                };
                //Act
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Question.AddRange(questions);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }
            //Assert
            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork = new UnitOfWork(context);
                var account    = unitOfWork.Account.GetByString("Triss");
                var path       = @"../../../../TietoFeedbackTool/ClientApp/src/assets/scripts/userSideScript.js";
                var Script     = unitOfWork.TrackingCode.GetScript(account.QuestionsKey, path);
                Assert.NotNull(Script);
                Assert.Contains("function checkDomain()", Script);
                unitOfWork.Dispose();
            }
        }
示例#16
0
        public void Get_ListOFQuestionByQuestionKeyAndDomain_Returns_SameList()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Get_ListOFQuestionByQuestionKeyAndDomain_Returns_SameList")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Julian Alfred Pankratz wicehrabia de Lettenhove"
                };
                var questions = new List <Question>
                {
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12645", QuestionText = "Do You like feedbacktool?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12745", QuestionText = "Are you free tonight?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12845", QuestionText = "Wanna go out for beer?", Enabled = true
                    }
                };
                //Act
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Question.AddRange(questions);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }
            //Assert
            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork     = new UnitOfWork(context);
                var account        = unitOfWork.Account.GetByString("Jaskier");
                var surveyByDomain = unitOfWork.TrackingCode.GetSurveyByDomain(account.QuestionsKey, "localhost:12745");
                var expected       = account.Questions.Where(x => x.Domain == "localhost:12745").ToList();
                Assert.Equal(expected, surveyByDomain);
                unitOfWork.Dispose();
            }
        }
        public void TestRemoveQuestion()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "TestRemoveQuestion")
                          .Options;

            //Arrange
            using (var context = new TietoFeedbackToolContext(options))
            {
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Beliar the god"
                };
                Question newQuestion = new Question()
                {
                    AccountLogin = "******", Domain = "localhost:44350", QuestionText = "Do You like feedbacktool?", Enabled = true
                };
                unitOfWork.Question.Add(newQuestion);
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }

            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork = new UnitOfWork(context);

                //Act
                var account  = unitOfWork.Account.GetByString("Beliar");
                var question = account.Questions[0];
                unitOfWork.Question.Remove(question);
                unitOfWork.Complete();

                //Assert
                Assert.Empty(account.Questions);
                unitOfWork.Dispose();
            }
        }
        public void Add_SingleAnswer_Returns_SameAnswer()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Add_SingleAnswer_Returns_SameAnswer")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Filippa Eilhart"
                };
                unitOfWork.Account.Add(newAccount);
                Question newQuestion = new Question {
                    AccountLogin = "******", Domain = "localhost:44444", QuestionText = "Do You like feedbacktool?", Enabled = true
                };
                unitOfWork.Question.Add(newQuestion);
                var          accid = newAccount.Questions[0].Id;
                PuzzleAnswer newOpenPuzzleAnswer = new PuzzleAnswer()
                {
                    QuestionId = accid, Answer = "Yes"
                };
                unitOfWork.PuzzleAnswer.Add(newOpenPuzzleAnswer);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }
            //Assert
            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork = new UnitOfWork(context);
                var account    = unitOfWork.Account.GetByString("Filippa");
                var answer     = account.Questions[0].PuzzleAnswers[0];
                Assert.Equal("Yes", answer.Answer);
                unitOfWork.Dispose();
            }
        }
        public void TestGetQuestion()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "TestGetQuestion")
                          .Options;

            //Arrange
            using (var context = new TietoFeedbackToolContext(options))
            {
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Richardo"
                };
                unitOfWork.Account.Add(newAccount);
                Question newQuestion = new Question()
                {
                    AccountLogin = "******", Domain = "localhost:44350", QuestionText = "Do You like feedbacktool?", Enabled = true
                };
                unitOfWork.Question.Add(newQuestion);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }

            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork = new UnitOfWork(context);

                //Act
                var account  = unitOfWork.Account.GetByString("Richard");
                var question = account.Questions[0];
                var expected = context.Question.Single(x => x.Id == account.Questions.SingleOrDefault().Id);

                //Assert
                Assert.Equal(expected, question);
                unitOfWork.Dispose();
            }
        }
        public void Update_Account_Returns_UpdatedAccount()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Update_Account_Returns_UpdatedAccount")
                          .Options;

            //Arrange
            using (var context = new TietoFeedbackToolContext(options))
            {
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "The Brutus"
                };
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }

            using (var context = new TietoFeedbackToolContext(options))
            {
                var     unitOfWork = new UnitOfWork(context);
                Account account    = new Account()
                {
                    Login = "******", Name = "Roman The Barbarian"
                };

                //Act
                unitOfWork.Account.UpdateAccount(account, "Brutus");
                unitOfWork.Complete();
                var updated = unitOfWork.Account.GetByString("Brutus");

                //Assert
                Assert.Equal("Brutus", updated.Login);
                Assert.Equal("Roman The Barbarian", updated.Name);
                unitOfWork.Dispose();
            }
        }
        public void Get_ListOfAllAnswers_Returns_SameList()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Get_ListOfAllAnswers_Returns_SameList")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Sabrina Glevissig z Ard Carraigh"
                };
                var questions = new List <Question>
                {
                    new Question {
                        AccountLogin = "******", Domain = "localhost:12345", QuestionText = "Do You like feedbacktool?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:22345", QuestionText = "Are you free tonight?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:32345", QuestionText = "Wanna go out for beer?", Enabled = true
                    }
                };
                var answers = new List <PuzzleAnswer>
                {
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "Yes"
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "No"
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 2, Answer = "Yes"
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 2, Answer = "No"
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 3, Answer = "Yes"
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 3, Answer = "No"
                    }
                };
                //Act
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Question.AddRange(questions);
                unitOfWork.PuzzleAnswer.AddRange(answers);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }
            //Assert
            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork = new UnitOfWork(context);
                var answers    = unitOfWork.PuzzleAnswer.GetAll();
                var expected   = context.PuzzleAnswers;
                Assert.Equal(expected, answers);
                unitOfWork.Dispose();
            }
        }
        public void Get_AnswerRatingList_Returns_TrueIfFindAnyAndIfReturnsIntendedValue()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Get_AnswerRatingList_Returns_TrueIfFindAnyAndIfReturnsIntendedValue")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Sheala de Tancarville"
                };
                var questions = new List <Question>
                {
                    new Question {
                        AccountLogin = "******", Domain = "localhost:42345", QuestionText = "Do You like feedbacktool?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:52345", QuestionText = "Are you free tonight?", Enabled = true
                    },
                    new Question {
                        AccountLogin = "******", Domain = "localhost:62345", QuestionText = "Wanna go out for beer?", Enabled = true
                    }
                };
                var answers = new List <PuzzleAnswer>
                {
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "Yes", Rating = 3
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "Yes", Rating = 1
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "Yes", Rating = 1
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "Yes", Rating = 1
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "Yes", Rating = 1
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "No", Rating = 3
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "No", Rating = 2
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "No", Rating = 2
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "No", Rating = 2
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "No", Rating = 4
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "No", Rating = 4
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "No", Rating = 4
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "No", Rating = 4
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "No", Rating = 4
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "No", Rating = 4
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "No", Rating = 4
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "No", Rating = 5
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 1, Answer = "No", Rating = 5
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 2, Answer = "Yes", Rating = 3
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 2, Answer = "No", Rating = 3
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 2, Answer = "Yes", Rating = 4
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 2, Answer = "No", Rating = 4
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 3, Answer = "Yes", Rating = 2
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 3, Answer = "Yes", Rating = 2
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 3, Answer = "No", Rating = 3
                    },
                    new PuzzleAnswer()
                    {
                        QuestionId = 3, Answer = "No", Rating = 3
                    }
                };
                //Act
                unitOfWork.Account.Add(newAccount);
                unitOfWork.Question.AddRange(questions);
                unitOfWork.PuzzleAnswer.AddRange(answers);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }
            //Assert
            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork        = new UnitOfWork(context);
                var answersRatingList = unitOfWork.PuzzleAnswer.GetAnswerRatingList(1);
                Assert.NotNull(answersRatingList);
                Assert.Equal(4, answersRatingList[0]);
                Assert.Equal(3, answersRatingList[1]);
                Assert.Equal(2, answersRatingList[2]);
                Assert.Equal(7, answersRatingList[3]);
                Assert.Equal(2, answersRatingList[4]);

                unitOfWork.Dispose();
            }
        }