예제 #1
0
        public void DeleteBadgeNonAdmin()
        {
            var mockPrincipal = new Mock <ICslaPrincipal>();

            mockPrincipal.Setup(i => i.IsInRole(Common.Enums.PermissionType.Administrator.ToString())).Returns(false);
            Csla.ApplicationContext.User = mockPrincipal.Object;

            var builder = new ContainerBuilder();

            builder.RegisterType(typeof(LeaderboardItemDAL)).As(typeof(ILeaderboardItemDAL));
            builder.RegisterGeneric(typeof(ObjectFactory <>)).As(typeof(IObjectFactory <>));
            IoC.Container = builder.Build();

            try
            {
                var badgeDelete = BadgeDelete.DeleteBadgeAsync(1);
                badgeDelete.Wait();
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual(e.InnerException.Message, "User not authorized to execute object type BadgeDelete");
                throw;
            }
        }
예제 #2
0
        public void DeleteBadgeAdmin()
        {
            var mockPrincipal = new Mock <ICslaPrincipal>();

            mockPrincipal.Setup(i => i.IsInRole(Common.Enums.PermissionType.Administrator.ToString())).Returns(true);
            Csla.ApplicationContext.User = mockPrincipal.Object;

            var builder = new ContainerBuilder();

            builder.RegisterType(typeof(LeaderboardItemDAL)).As(typeof(ILeaderboardItemDAL));
            builder.RegisterGeneric(typeof(ObjectFactory <>)).As(typeof(IObjectFactory <>));
            IoC.Container = builder.Build();

            var badgeDelete = BadgeDelete.DeleteBadgeAsync(1);

            badgeDelete.Wait();

            Assert.AreEqual(badgeDelete.Status, TaskStatus.RanToCompletion);
        }
        public virtual async Task <ActionResult> Delete(int badgeAwardId)
        {
            await BadgeDelete.DeleteBadgeAsync(badgeAwardId);

            return(null);
        }