Example #1
0
        public async Task <IActionResult> Report(int id, string reason)
        {
            var userId  = userManager.GetUserId(User);
            var message = messageContext.Messages
                          .Single(c => c.Id == id && c.RecevierId == userId);

            if (message.IsReported)
            {
                return(Ok());
            }

            message.IsReported = true;

            var report = new ReportMessage
            {
                UserId     = userId,
                MessageId  = id,
                Reason     = reason,
                ReportTime = DateTime.UtcNow
            };

            messageContext.Add(report);
            await messageContext.SaveChangesAsync();

            return(Ok());
        }
        public void Dump_GetsNullParameter_ThrowsException()
        {
            var target = new MessageContext();

            target.Add("Fact");

            Action act = () => target.Dump(null);

            act.Should().Throw <ArgumentNullException>();
        }
        public async Task <IActionResult> Create([Bind("MessageId,MessageText")] Message message)
        {
            if (ModelState.IsValid)
            {
                _context.Add(message);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(message));
        }
        public void Get_ReturnsValidMessageList()
        {
            var target = new MessageContext();

            target.Add("Fact");

            var messageList = target.Get() as IList <string>;

            if (messageList == null)
            {
                throw new XunitException("Message list was null.");
            }

            messageList.Should().NotBeNull();
        }
        public void Add_ProperlyAddsMessagesToList()
        {
            var target = new MessageContext();

            target.Add("Fact");

            var messageList = target.Get() as IList <string>;

            if (messageList == null)
            {
                throw new XunitException("Message list was null.");
            }

            messageList.Count.Should().Be(1);
        }
        public void Clear_RemovesMessages()
        {
            var target = new MessageContext();

            target.Add("Fact");
            target.Clear();

            var messageList = target.Get() as IList <string>;

            if (messageList == null)
            {
                throw new XunitException("Message list was null.");
            }

            messageList.Count.Should().Be(0);
        }
Example #7
0
        public async Task <IActionResult> Index(ProfileVM viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var message = new Message
            {
                RecevierId = viewModel.PublicMessage.ReceiverId,
                Text       = viewModel.PublicMessage.Text,
                SentTime   = DateTime.UtcNow,
                SenderId   = userManager.GetUserId(User) ?? "Not Provided"
            };

            messageContext.Add(message);
            await messageContext.SaveChangesAsync();

            return(RedirectToAction(nameof(Success)));
        }
        public void Dump_GetsMessageList_OutputsCorrectNumberOfEntries()
        {
            var target = new MessageContext();

            target.Add("Fact");

            var callbackTimes = 0;

            var logger = A.Fake <ILogWrapper>();

            A.CallTo(() => logger.Info(A <object> .Ignored)).Invokes(() => callbackTimes++);

            target.Dump(logger);

            var messageList = target.Get() as IList <string>;

            if (messageList == null)
            {
                throw new XunitException("Message list was null.");
            }

            messageList.Count.Should().Be(0);
            callbackTimes.Should().Be(1);
        }