public void AddWhenAssignmentIsValidShouldAddAssignment()
        {
            var repository = Mock.Create <ITwsData>();

            var assignmentEntity = Entities.GetValidAssignment();
            var teamWorkEntity   = Entities.GetValidTeamWork();

            teamWorkEntity.Assignments.Add(assignmentEntity);
            IList <TeamWork> teamworkEntities = new List <TeamWork>();

            teamworkEntities.Add(teamWorkEntity);
            IList <Assignment> assignmentEntities = new List <Assignment>();

            assignmentEntities.Add(assignmentEntity);

            Mock.Arrange(() => repository.Assignments.All())
            .Returns(() => assignmentEntities.AsQueryable());
            Mock.Arrange(() => repository.TeamWorks.All())
            .Returns(() => teamworkEntities.AsQueryable());

            var controller = new AssignmentController(repository);

            var assignmentModels = controller.ByTeamwork(0);
            var negotiatedResult = assignmentModels as OkNegotiatedContentResult <IQueryable <AssignmentModel> >;

            Assert.IsNotNull(negotiatedResult);
            Assert.AreEqual <string>(assignmentEntity.Name, negotiatedResult.Content.FirstOrDefault().Name);
        }
Example #2
0
        public async void AssignmentControllerTest()
        {
            var options = new DbContextOptionsBuilder <AppDbContext>()
                          .UseInMemoryDatabase(databaseName: "yeetus2").Options;

            using (var context = new AppDbContext(options))
            {
                Repository repo = new Repository(context);
                var        _AssignmentController = new AssignmentController(repo);
                Assignment tempAssignmentOne     = new Assignment();
                tempAssignmentOne.AssignmentId = 1;
                tempAssignmentOne.EnrollmentId = 1;
                tempAssignmentOne.Grade        = 80;
                tempAssignmentOne.Title        = "test";

                await _AssignmentController.CreateAssignmentAsync(tempAssignmentOne);

                ActionResult <List <Assignment> > testList = _AssignmentController.GetAll().Result;
                testList = testList.Value;
                Assert.NotNull(testList);
                ActionResult <Assignment> testList2 = _AssignmentController.Get(1).Result;
                Assert.NotNull(testList2);
                tempAssignmentOne.Title = "idk";
                await repo.EditAssignmentScoreAsync(tempAssignmentOne);

                Assert.Equal(80, tempAssignmentOne.Grade);
                Assert.Equal("idk", (repo.GetAssignmentAsync(1).Result.Title));
            }
        }
Example #3
0
        protected void dlCommandItem(object sender, DataListCommandEventArgs e)
        {
            string filePath = ((Label)e.Item.FindControl("lblAFileLocation")).Text;

            if (e.CommandName == "View")
            {
                DownloadFile(filePath, true);
            }
            else
            {
                //Call to delete the assignment
                //Get the assignment ID
                Int32 assignmentID = Convert.ToInt32(((Label)e.Item.FindControl("lblAssignmentID")).Text);
                //Get file location of the Assignment.
                string filePathToDelete = ((Label)e.Item.FindControl("lblAFileLocation")).Text;

                if (SubmissionController.GetItem(assignmentID) == null)
                {
                    AssignmentController.Delete(assignmentID);
                    File.Delete(filePath);
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "errorDelete",
                                                       "alert('This assignment cannot be deleted!!!');",
                                                       true);
                }
                Helper.ViewAssignment(dlistAssignment, Session["CourseID"].ToString());
            }
        }
Example #4
0
        public void Can_List_Assignments()
        {
            // Arrange
            Mock <IAssignmentRepository> mock = new Mock <IAssignmentRepository>();

            mock.Assignments.Returns(Assignment[3] = new Assignment {
                Headline = "A1", Headline = "A2", Headline = "A3"
            });



            /* {
             *   new Assignment() = { Headline = "A1"};
             *   new Assignment() = { Headline = "A2"};
             *   new Assignment() = { Headline = "A3"};
             * }
             */

            AssignmentController controller = new AssignmentController(mock.Object());


            // Act
            Assignment[] result = (controller.List() as ViewModel).ToArray();

            // Assert
            Assert.Equal(result.Length, 3);
            Assert.True(result[0].Headline == "A1");
            Assert.True(result[1].Headline == "A2");
            Assert.True(result[2].Headline == "A3");
        }
        public async Task ShouldGetAvailabityDoctor()
        {
            var doctorId = 3;
            var body     = new TimeFreeModel()
            {
                InitialDate = "1900-01-01T08:00:00",
                EndDate     = "1900-01-01T17:00:00"
            };
            var assignmentController = new AssignmentController(new Services.assignmentServices())
            {
                Request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Get,
                    Content    = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"),
                    RequestUri = new Uri($"{url}/doctors/{doctorId}/availables")
                }
            };

            assignmentController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            var response = assignmentController.getDoctorTimeFree(doctorId, body);
            var result   = await response.ExecuteAsync(new System.Threading.CancellationToken());

            Assert.AreEqual(result.StatusCode, HttpStatusCode.OK);
        }
 public AssignmentControllerTests() : base(false)
 {
     _controller = new AssignmentController(new AssignmentService(Db), Db)
     {
         ControllerContext = HttpResponseTest.SetupMockControllerContext()
     };
 }
Example #7
0
        public UnitTest1()
        {
            IServiceCollection services = new ServiceCollection();

            services.AddApplicationServices();
            services.AddTransient <AssignmentController>();
            services.AddTransient <InvoiceController>();
            services.AddTransient <EmployeeController>();
            services.AddTransient <CustomerController>();
            services.AddTransient <PaymentController>();
            services.AddTransient <PayoutController>();

            _autofacContainer = services.AddAutofacContainer();
            _serviceProvider  = new AutofacServiceProvider(_autofacContainer);

            _queryProcessor    = _serviceProvider.GetService <IQueryProcessor>();
            _assignmentService = _serviceProvider.GetService <IAssignmentService>();
            _paymentService    = _serviceProvider.GetService <IPaymentService>();

            _assignmentController = _serviceProvider.GetService <AssignmentController>();
            _invoiceController    = _serviceProvider.GetService <InvoiceController>();
            _employeeController   = _serviceProvider.GetService <EmployeeController>();
            _customerController   = _serviceProvider.GetService <CustomerController>();
            _paymentController    = _serviceProvider.GetService <PaymentController>();
            _payoutController     = _serviceProvider.GetService <PayoutController>();
        }
 public void Init()
 {
     _contextMock = new Mock <IDbContext>();
     _WebSecurity = new Mock <IWebSecurity>();
     _logmod      = new LogonModel();
     _controller  = new AssignmentController(_contextMock.Object);
     MapperConfig.Configure();
 }
Example #9
0
        public void Get_ShouldReturnAllAssignments()
        {
            AssignmentController controller      = new AssignmentController(new MockRepository());
            List <string>        testAssignments = GetTestAssignments();

            var result = (controller.Get().Result as OkObjectResult)?.Value as IEnumerable <Assignment>;

            Assert.AreEqual(testAssignments.Count, result.Count());
        }
Example #10
0
        public static void GetMainMenu()
        {
            bool inValidEntry = true;

            while (inValidEntry)
            {
                Console.WriteLine("Enter 1 To Enter A New Grade");
                Console.WriteLine("Enter 2 To View Homework Grades");
                Console.WriteLine("Enter 3 To View Test Grades");
                Console.WriteLine("Enter 4 To Edit Students");
                Console.WriteLine("Enter 5 To Exit ");

                try
                {
                    var entry = int.Parse(Console.ReadLine());

                    if (entry < 1 || entry > 5)
                    {
                        continue;
                    }
                    else
                    {
                        inValidEntry = false;
                    }

                    switch (entry)
                    {
                    case 1:
                        AssignmentController.AddAssignmentMenu();
                        break;

                    case 2:
                        AssignmentController.GetHomeworks();
                        break;

                    case 3:
                        AssignmentController.GetTests();
                        break;

                    case 4:
                        StudentController.GetStudentMenu();
                        break;

                    case 5:
                        Environment.Exit(0);
                        break;

                    default:
                        break;
                    }
                }catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Example #11
0
        public void Delete_ShouldDeleteLastAssignment()
        {
            AssignmentController controller = new AssignmentController(new MockRepository());
            var testAssignments             = GetTestAssignments();

            var result = (controller.Delete(3)
                          .Result.Result as OkObjectResult)?.Value as Assignment;

            Assert.AreEqual(testAssignments.Last(), result.Text);
        }
Example #12
0
 public IActionResult TimesheetView(int idAssignment, int idEmployee)
 {
     ViewData["EnableControls"] = false;
     ViewData["Timesheet"] = JsonConvert.SerializeObject(AssignmentController.GetTimesheet(_context, idEmployee, idAssignment), new JsonSerializerSettings()
     {
         NullValueHandling = NullValueHandling.Ignore,
         ContractResolver = new CamelCasePropertyNamesContractResolver()
     });
     return View("timesheet");
 }
Example #13
0
        public void Add_ShouldAddAssignment()
        {
            AssignmentController controller = new AssignmentController(new MockRepository());

            Assignment post = (controller.Post(new Assignment()
            {
                Text = "take a nap"
            })
                               .Result.Result as OkObjectResult)?.Value as Assignment;

            Assert.AreEqual(4, post.Priority);
        }
Example #14
0
        public void Prioritize_ShouldPrioritize()
        {
            AssignmentController controller = new AssignmentController(new MockRepository());
            var testAssignments             = GetTestAssignments();

            var testAssignment = new Assignment {
                Text = testAssignments.Skip(1).First(), Priority = 3
            };
            Assignment assignment = (controller.Prioritize(testAssignment)
                                     .Result.Result as OkObjectResult)?.Value as Assignment;

            Assert.AreEqual(3, assignment.Priority);
        }
Example #15
0
        public void ReturnDefaultView()
        {
            // Arange
            var assignmentServiceMock      = new Mock <IAssignmentService>();
            var storeMock                  = new Mock <IUserStore <ApplicationUser> >();
            var applicationUserManagerMock = new Mock <ApplicationUserManager>(storeMock.Object);

            var controller = new AssignmentController(assignmentServiceMock.Object, applicationUserManagerMock.Object);

            // Act && Assert
            controller
            .WithCallTo(c => c.ManageAssignments())
            .ShouldRenderDefaultView();
        }
Example #16
0
        private AssignmentController GetAssignmentController()
        {
            var controller =
                new AssignmentController(new AssignmentRepository(_mongoDatabase), new ImageBucketRepository(_mongoDatabase), new NotificationServicesMock());
            var urlMock = new Mock <IUrlHelper>();

            urlMock.Setup(_ =>
                          _.Link(It.Is <string>(routeName => routeName == "GetAssignment"), It.Is <object>(values => true)))
            .Returns((string routeName, object values) =>
            {
                var valuesDic = values.ToDictionary();
                return($"some-host/assignment/{valuesDic["id"]}");
            });
            controller.Url = urlMock.Object;
            return(controller);
        }
Example #17
0
        public void RedirectToAction()
        {
            // Assert
            var courseModel = new CourseNameViewModel();
            var serviceMock = new Mock <IAssignmentService>();

            var userStore       = new Mock <IUserStore <ApplicationUser> >();
            var userManagerMock = new Mock <ApplicationUserManager>(userStore.Object);

            var controller = new AssignmentController(serviceMock.Object, userManagerMock.Object);

            // Act && Assert
            controller
            .WithCallTo(c => c.AssignTo(courseModel))
            .ShouldRedirectTo <AdminController>(r => r.Home());
        }
        public AssignmentControllerUnitTest()
        {
            _projectId = Guid.NewGuid().ToString();

            AssignmentResponseDto assignmentOne = new AssignmentResponseDto();

            assignmentOne.Id             = Guid.NewGuid();
            assignmentOne.Name           = "Name";
            assignmentOne.Description    = "Desc";
            assignmentOne.DateOfCreation = DateTime.Now;
            assignmentOne.CreatedBy      = Guid.NewGuid();
            assignmentOne.Status         = "TODO";

            AssignmentResponseDto assignmentTwo = new AssignmentResponseDto();

            assignmentOne.Id             = Guid.NewGuid();
            assignmentOne.Name           = "Name Two";
            assignmentOne.Description    = "Desc Two";
            assignmentOne.DateOfCreation = DateTime.Now;
            assignmentOne.CreatedBy      = Guid.NewGuid();
            assignmentOne.Status         = "INPROGRESS";

            _assignments = new List <AssignmentResponseDto>();
            _assignments.Add(assignmentOne);
            _assignments.Add(assignmentTwo);

            _assignmentServiceMock = new Mock <IAssignmentService>();

            _createAssignment             = new CreateAssignmentRequestDto();
            _createAssignment.Name        = "Name";
            _createAssignment.Description = "Desc";
            _createAssignment.CreatedBy   = _assignments.ElementAt(0).CreatedBy;
            _createAssignment.Status      = "TODO";

            _assignmentServiceMock.Setup(svc => svc.RetrieveById(_assignments.ElementAt(0).Id.ToString()))
            .ReturnsAsync(_assignments.ElementAt(0));

            _assignmentServiceMock.Setup(svc => svc.RetrieveAll(_projectId))
            .ReturnsAsync(_assignments);

            _assignmentServiceMock.Setup(svc => svc.CreateAssignment(_createAssignment))
            .ReturnsAsync(_assignments.ElementAt(0));

            _controller = new AssignmentController(_assignmentServiceMock.Object);
        }
Example #19
0
        public void CallGetAllCoursesOnce()
        {
            // Arange
            var assignmentServiceMock      = new Mock <IAssignmentService>();
            var storeMock                  = new Mock <IUserStore <ApplicationUser> >();
            var applicationUserManagerMock = new Mock <ApplicationUserManager>(storeMock.Object);

            var courses = new List <Course>();

            assignmentServiceMock.Setup(m => m.GetAllCourses()).Returns(courses);

            var controller = new AssignmentController(assignmentServiceMock.Object, applicationUserManagerMock.Object);

            // Act
            controller.AssignCourse();

            // Assert
            assignmentServiceMock.Verify(a => a.GetAllCourses(), Times.Once);
        }
        public async Task ShouldGetAssignmentDoctor()
        {
            var doctorId             = 3;
            var assignmentController = new AssignmentController(new Services.assignmentServices())
            {
                Request = new HttpRequestMessage
                {
                    Method = HttpMethod.Get,

                    RequestUri = new Uri($"{url}/doctors/{doctorId}/assigned")
                }
            };

            assignmentController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            var response = assignmentController.getAssignedDoctor(doctorId);
            var result   = await response.ExecuteAsync(new System.Threading.CancellationToken());

            Assert.AreEqual(result.StatusCode, HttpStatusCode.OK);
        }
Example #21
0
        public void ReturnDefaultViewWithCorrectModel()
        {
            // Arange
            var assignmentServiceMock      = new Mock <IAssignmentService>();
            var storeMock                  = new Mock <IUserStore <ApplicationUser> >();
            var applicationUserManagerMock = new Mock <ApplicationUserManager>(storeMock.Object);

            var courses = new List <Course>();

            assignmentServiceMock.Setup(m => m.GetAllCourses()).Returns(courses);

            var expectedModel = new ListAssignmentViewModel()
            {
                Courses = courses
            };

            var controller = new AssignmentController(assignmentServiceMock.Object, applicationUserManagerMock.Object);

            // Act & Assert
            controller
            .WithCallTo(c => c.AssignCourse())
            .ShouldRenderDefaultView()
            .WithModel <ListAssignmentViewModel>(m => Assert.AreSame(expectedModel.Courses, m.Courses));
        }
Example #22
0
        public void GetAssignments_ShouldReturnAllAssignments()
        {
            var context = new AppContext();


            context.Details.Add(new Details {
                Assignment_ID = 2, Assignment_Name = "Website", Client_Name = "Telia", Percentage = "80%", Start_Date = DateTime.Parse("2016-07-21"), End_Date = DateTime.Parse("2017-03-31"), Comment = "Website for Telia", Consultant_Name = "fayek"
            });

            context.Details.Add(new Details {
                Assignment_ID = 2, Assignment_Name = "Website", Client_Name = "Telia", Percentage = "80%", Start_Date = DateTime.Parse("2016-07-21"), End_Date = DateTime.Parse("2017-03-31"), Comment = "Website for Telia", Consultant_Name = "fayek"
            });

            context.Details.Add(new Details {
                Assignment_ID = 2, Assignment_Name = "Website", Client_Name = "Telia", Percentage = "80%", Start_Date = DateTime.Parse("2016-07-21"), End_Date = DateTime.Parse("2017-03-31"), Comment = "Website for Telia", Consultant_Name = "fayek"
            });


            var controller = new AssignmentController(context);
            var result     = controller.Get();

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Count);
        }
Example #23
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            Assignment assignment = new Assignment();

            assignment.AssignmentId = -1;
            assignment.CourseId     = Session["courseID"].ToString();
            //Check whether or not the title is specified.
            if (txtboxAssignmentTitle.Text == String.Empty)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "errorTitle",
                                                   "alert('Please provide title of the assignment!!!');", true);
            }
            else
            {
                if (txtboxDueDate.Text == String.Empty)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "errorTitle",
                                                       "alert('Please provide due date of the assignment submission!!!');",
                                                       true);
                }
                else
                {
                    assignment.ATitle  = txtboxAssignmentTitle.Text;
                    assignment.DueDate = Convert.ToDateTime(txtboxDueDate.Text);
                    //Check whether or not there is valid file to upload.
                    if (fileuploadAssignment.HasFile)
                    {
                        if (fileuploadAssignment.PostedFile.ContentType.ToLower() == "application/pdf" ||
                            fileuploadAssignment.PostedFile.ContentType.ToLower() == "application/msword")
                        {
                            //Append date and time in the filename to make it unique.
                            string filename = Path.GetFileNameWithoutExtension(fileuploadAssignment.FileName) +
                                              DateTime.Now.ToString("_yyyy_mm_dd_HH_mm_ss");
                            string extension = Path.GetExtension(fileuploadAssignment.FileName);
                            string directory = Server.MapPath("~/CourseMaterials/" + Session["courseID"] + "/Assignment");
                            //Create directory if no folder to save the lecture note
                            if (!Directory.Exists(directory))
                            {
                                Directory.CreateDirectory(directory);
                            }
                            assignment.AFileLocation = directory + "/" + filename + extension;
                            fileuploadAssignment.SaveAs(assignment.AFileLocation);
                            ClientScript.RegisterStartupScript(this.GetType(), "successUpload",
                                                               "alert('Uploaded successfully!!!');", true);
                            AssignmentController.Save(assignment);
                            Response.Redirect("~/InstructorSite/formManageAssignment.aspx");
                        }
                        else  //If the file format is invalid.
                        {
                            ClientScript.RegisterStartupScript(this.GetType(), "fileFormatError",
                                                               "alert('File format error: Only pdf or doc files are allowed!!!');",
                                                               true);
                        }
                    }
                    else //If the path doesn't contain any file
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "failUpload",
                                                           "alert('Please specify the file to upload.!!!');", true);
                    }
                }
            }
        }
 public AssignmentControllerTests()
 {
     repo      = Substitute.For <IAssignmentRepository>();
     underTest = new AssignmentController(repo);
 }
Example #25
0
 public AssignmentTest()
 {
     _service    = new AssignmentFake();
     _controller = new AssignmentController(_service);
 }