Esempio n. 1
0
        public void CreateNewsViewDataIsNotNullTest()
        {
            //Arrange
            var newsController = new NewsController(newsService: null, userManager: null, mapper: null);

            //Act
            var result = newsController.CreateNews() as ViewResult;

            //Assert
            Assert.IsNotNull(result?.ViewData);
        }
Esempio n. 2
0
        public void CreatingItemWithIncorrectData_ShouldReturnBadRequest()
        {
            var controller = new NewsController(this.context);

            this.SetupController(controller);

            // Forcing validation error
            controller.ModelState.AddModelError("Title", "Title should be atleast 3 symbols.");

            var newsBindingModel = new NewsBindingModel
            {
                Title   = "1",
                Content = "2222"
            };

            var response = controller.CreateNews(newsBindingModel).ExecuteAsync(CancellationToken.None).Result;

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
Esempio n. 3
0
        public void CreatingItem_ShouldCreateTheItemAndReturnIt()
        {
            var controller = new NewsController(this.context);

            this.SetupController(controller);

            var newsBindingModel = new NewsBindingModel
            {
                Title   = "Fire in the motel",
                Content = "The fire fighters are doing their best."
            };

            var response = controller.CreateNews(newsBindingModel).ExecuteAsync(CancellationToken.None).Result;

            var responseNews = response.Content.ReadAsAsync <NewsBindingModel>().Result;

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            Assert.AreEqual(newsBindingModel.Title, responseNews.Title);
            Assert.AreEqual(newsBindingModel.Content, responseNews.Content);
        }
Esempio n. 4
0
    public void OnGameStarted(Database.Database db, DateTime date,
                              GameDevCompany playedCompany)
    {
        database      = db;
        playerCompany = playedCompany;
        gameDateTime  = date;

        // load script functions
        scriptFunctions = Function <bool> .DefaultFunctions();

        scriptGlobalVariables = GameVariables();
        // additional local variables
        Assert.IsTrue(ScriptContext.AddLocalVariable(this,
                                                     "Employee_HiringCost", new FloatSymbol(0), true));
        Assert.IsTrue(ScriptContext.AddLocalVariable(this,
                                                     "Employee_Salary", new FloatSymbol(0), true));
        // parser context
        ParserContext parserContext = new ParserContext {
            Grammar         = Grammar.DefaultGrammar(),
            LocalVariables  = scriptVariables,
            GlobalVariables = scriptGlobalVariables,
            Functions       = scriptFunctions,
        };

        // test
        const string script     = @"
            //{
                let b: int = b;
            //}
            b
        ";
        Executable   executable = Executable.FromScript(script, parserContext);

        if (executable != null)
        {
            int result;
            executable.ExecuteExpecting(this, out result);
            Debug.LogWarning($"===> executable result = {result}");
        }

        // scripts parsing
        eventsController.CreateEvents(db.Events.Collection, parserContext);
        playerCompany.Init(database.Skills, parserContext);
        engineFeaturesController.CreateFeatures(db.EngineFeatures.Collection,
                                                parserContext);
        engineFeaturesController.CheckFeatures(this);
        newsController.CreateNews(db.News.Collection, date);

        // events OnInit calls
        Assert.IsTrue(eventsController.InitEvents(this));

        float    hiringCost;
        Employee employee = playedCompany.EmployeesManager.GenerateRandomEmployee(
            this,
            db.HiringMethod.FindById("CompSciGraduates"),
            db.Names.FindById("CommonNamesUSA"),
            db.Skills,
            out hiringCost);

        playedCompany.AddEmployee(employee);
        Debug.Log($"Generated Random Employee : hiring cost = {hiringCost}.");
    }