public void Conference_Add()
        {
            // Arrange
            string section = "DPRO";
            var    info    = new InfoItem
            {
                Name     = "DevPRO",
                City     = "Tomsk",
                Location = "ul. Naberejnaya reki Ushaiky, 12 (IAM TSU)"
            };

            using (var context = GetContextWithData())
                using (var controller = new ConferenceController(context))
                {
                    // Act
                    var result = controller.Create(section, info);

                    // Assert
                    var createdResult = result.Should().BeOfType <CreatedAtRouteResult>().Subject;
                    var item          = createdResult.Value.Should().BeAssignableTo <ConferenceItem>().Subject;

                    item.Section.Should().Be("DPRO");
                    item.Info.Name.Should().Be("DevPRO");
                    item.Info.City.Should().Be("Tomsk");
                    item.Info.Location.Should().Be("ul. Naberejnaya reki Ushaiky, 12 (IAM TSU)");
                }
        }
Ejemplo n.º 2
0
        public void Controller_AddConference_ReturnsNewConferenceAsLast()
        {
            var repository = ServiceProvider.GetRequiredService <IConferenceRepository>();
            var controller = new ConferenceController(repository);

            // create new conference
            var result = controller.Create(new Web.Models.ConferenceViewModel
            {
                Name        = "test Conf",
                Description = "hello"
            }) as RedirectToActionResult;

            Assert.Equal("Conference", result.ControllerName);
            Assert.Equal("Index", result.ActionName);

            // get last conference
            var conferenceList      = (controller.Index() as ViewResult).Model as IEnumerable <ConferenceViewModel>;
            var conferenceViewModel = conferenceList.Last();

            Assert.Equal("test Conf", conferenceViewModel.Name);
            Assert.Equal("hello", conferenceViewModel.Description);
        }
Ejemplo n.º 3
0
        public void Create_WithAlreadyUsedHashTag_Should_ReturnViewAndAddModelError()
        {
            _context.Conferences.Add(new Conference()
            {
                HashTag = "abcde", Name = "test", Abstract = "test", StartDate = DateTime.Now, EndDate = DateTime.Now, TimeZoneId = "test", AvailableToPublic = false
            });
            _context.SaveChangesWithErrors();

            var conferenceController = new ConferenceController(_context);

            var newConference = new Conference()
            {
                HashTag = "abcde"
            };
            var result = conferenceController.Create(newConference)
                         .As <ViewResult>();

            result.ViewData.ModelState["HashTag"]
            .Errors
            .Count
            .Should()
            .Be(1);
        }
        public void Conference_Add_Invalid()
        {
            // Arrange
            string section = "DPRODPRO";
            var    info    = new InfoItem
            {
                Name     = "DevPRO",
                City     = "Tomsk",
                Location = "ul. Naberejnaya reki Ushaiky, 12 (IAM TSU)"
            };

            using (var context = GetContextWithData())
                using (var controller = new ConferenceController(context))
                {
                    // Act
                    var result = controller.Create(section, info);

                    // Assert
                    var createdResult = result.Should().BeOfType <BadRequestObjectResult>().Subject;
                    var item          = createdResult.Value.Should().BeAssignableTo <SerializableError>().Subject;
                    item.ContainsKey("Section").Should().Be(true);
                }
        }