Exemplo n.º 1
0
        public async System.Threading.Tasks.Task Create_OnPost_BookShouldBeAddedAsync()
        {
            // Arrange
            var builder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "InMemoryDb_Create");
            var context = new ApplicationDbContext(builder.Options);

            Seed(context);

            // Act
            var model = new CreateModel(context);

            var book = new Book()
            {
                Name   = "NameTest",
                ISBN   = "ISBNTsst",
                Author = "AuthorTest"
            };

            await model.OnPost(book);

            // Assert
            var books = await context.Books.ToListAsync();

            Assert.Equal(4, books.Count);
            Assert.Matches(books[3].Name, "NameTest");
        }
        public void OnPost_AddsSolutionToTheDatabase()
        {
            var mockUserManager = TestsUserManager.GetUserManager();

            var page = new CreateModel(this.dbContext, mockUserManager.Object, TestsAutoMapper.GetMapper());

            page.PageContext = new PageContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = new ClaimsPrincipal(new ClaimsIdentity(new[]
                    {
                        new Claim(ClaimTypes.Role, WebConstants.AdminRole)
                    }))
                }
            };

            page.Model = new SolutionCreationBindingModel
            {
                Title   = "Title",
                Content = "Content"
            };

            var result = page.OnPost();

            var lastRequest = this.dbContext.Solutions.LastOrDefault();

            Assert.IsNotNull(lastRequest);
            Assert.IsTrue(lastRequest.Content == page.Model.Content && lastRequest.Content == page.Model.Content);
        }
Exemplo n.º 3
0
        public void EnterRace()
        {
            CreateModel cm = new CreateModel();

            var boat = new BoatsTidy("Luke Stanislaus", "Laser", "162872", "", 0, "");

            cm.Boats         = boat;
            cm.Boatandnumber = "Laser, 162872";

            var str = "2nd evening Series Race 9abc1232018-08-08 19:00:00";

            cm.Race = str;
            Assert.IsTrue(cm.OnPost().IsCompletedSuccessfully);
            var      str1 = str.Split("abc123");
            Calendar cal  = new Calendar(str1[0], "", Convert.ToDateTime(str1[1]));



            Action act = new Action(Act);

            Assert.IsFalse(Assert.ThrowsException <Exception>(act) != new Exception());
        }
Exemplo n.º 4
0
        public static void Test_AddNewUser_Succeeds()
        {
            const int    IpAddressInt    = 0x2414188f;
            const string IpAddressString = "143.24.20.36";

            const string SignupUrl = "[Signup URL]";

            var currentInstant        = 9.May(2019).At(10, 14, 10).Utc();
            var expectedExpiryInstant = 10.May(2019).At(10, 14, 10).Utc();

            // Arrange
            // Set up clock
            var mockClock = new FakeClock(currentInstant);

            // Set up email repository
            var mockEmailRepository = new Mock <IEmailRepository>(MockBehavior.Strict);

            mockEmailRepository.Setup(r => r.AddToQueue(It.IsAny <IEmailTemplate>()));

            // Set up HTTP context accessor
            var httpContextAccessor = TestHelpers.CreateHttpContextAccessor(IpAddressInt);

            // Set up registration token repository
            var mockRegistrationTokenRepository = new Mock <IRegistrationTokenRepository>(MockBehavior.Strict);

            mockRegistrationTokenRepository.Setup(r => r.AddRegistrationToken(It.IsAny <RegistrationToken>()));

            // Set up model
            var httpContext = new DefaultHttpContext();

            var actionContext = new ActionContext(
                httpContext, new RouteData(), new PageActionDescriptor(), new ModelStateDictionary());

            var mockTempDataDictionary = new Mock <ITempDataDictionary>();

            var mockUrlHelper = new Mock <UrlHelper>(actionContext);

            mockUrlHelper
            .Setup(u => u.RouteUrl(It.IsAny <UrlRouteContext>()))
            .Returns(SignupUrl);

            // Act
            const string EmailAddress = "[email protected]";

            var model = new CreateModel(
                mockClock,
                mockEmailRepository.Object,
                httpContextAccessor,
                mockRegistrationTokenRepository.Object)
            {
                Input = new CreateModel.InputModel {
                    Email = EmailAddress, ConfirmEmail = EmailAddress
                },
                TempData = mockTempDataDictionary.Object,
                Url      = mockUrlHelper.Object
            };

            model.OnPost();

            // Assert
            mockEmailRepository.Verify(
                r => r.AddToQueue(It.Is <Signup>(e =>
                                                 e.To == EmailAddress &&
                                                 e.HtmlBody.Contains(SignupUrl) && e.HtmlBody.Contains(IpAddressString) &&
                                                 e.PlainTextBody.Contains(SignupUrl) && e.PlainTextBody.Contains(IpAddressString))),
                Times.Once);

            mockRegistrationTokenRepository.Verify(
                r => r.AddRegistrationToken(It.Is <RegistrationToken>(t =>
                                                                      !string.IsNullOrEmpty(t.Token) &&
                                                                      t.ExpiryTime == expectedExpiryInstant)),
                Times.Once);

            mockTempDataDictionary.VerifySet(d => d["Result"] = "Email will be sent.", Times.Once);
        }