示例#1
0
        [TestMethod] public void Post_MAl_Bad_request_Modelstate()
        {

            var commandBus = new Mock<IVaktLogikk>();
            commandBus.Setup(c => c.RegistrerMal(It.IsAny<MalerSkjema>(),It.IsAny<string>())).Returns(true);
            // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
            var httpConfiguration = new HttpConfiguration();
            WebApiConfig.Register(httpConfiguration);
            var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
                new HttpRouteValueDictionary { { "controller", "BrukerApi" } });
            var controller = new MalerController(commandBus.Object)
            {
                Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/Maler/")
                {
                    Properties =
            {
                { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
                { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
            }
                }
            };
            MalerSkjema nyMal = new MalerSkjema();
            nyMal.startTid = "";
            // The ASP.NET pipeline doesn't run, so validation don't run. 
            controller.ModelState.AddModelError("startTIid", "mock error message");
            var response = controller.Post(nyMal);
            // Assert
            commandBus.Verify(e => e.RegistrerMal(nyMal,"brukernavn"), Times.Never);
            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
            // Act

        }
示例#2
0
 public void Post_Mal_Ok()
 {
     MalerSkjema nyMal = new MalerSkjema()
     {
         ProsjektId = 1,
         Tittel = "Dagvakt1",
         startTid = "07.30",
         sluttTid = "14.45"
     };
     var commandBus = new Mock<IVaktLogikk>();
     commandBus.Setup(c => c.RegistrerMal(It.IsAny<MalerSkjema>(), It.IsAny<string>())).Returns(true);
     // Mapper.CreateMap<CategoryFormModel, CreateOrUpdateCategoryCommand>();
     var httpConfiguration = new HttpConfiguration();
     WebApiConfig.Register(httpConfiguration);
     var httpRouteData = new HttpRouteData(httpConfiguration.Routes["DefaultApi"],
         new HttpRouteValueDictionary { { "controller", "Maler" } });
     var controller = new MalerController(commandBus.Object)
     {
         Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/Maler/")
         {
             Properties =
     {
         { HttpPropertyKeys.HttpConfigurationKey, httpConfiguration },
         { HttpPropertyKeys.HttpRouteDataKey, httpRouteData }
     }
         }
     };
     // Act
     var response = controller.Post(nyMal);
     // Assert
     Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
      Assert.AreEqual(string.Format("http://localhost/api/Maler"), response.Headers.Location.ToString());
 }
示例#3
0
 // POST api/KalenderApi
 public HttpResponseMessage Post(MalerSkjema mal)
 {
     string userName = User.Identity.Name;
     if (ModelState.IsValid)
     {
         bool ok = _VaktBLL.RegistrerMal(mal, userName);
         if (ok)
         {
             var response = Request.CreateResponse(HttpStatusCode.Created, mal);
             string uri = Url.Link("DefaultApi",null);
             response.Headers.Location = new Uri(uri);
             return response;
         }
         return new HttpResponseMessage()
         {
             StatusCode = HttpStatusCode.NotFound,
             Content = new StringContent("Kunne ikke sette inn databasen")
         };
     }
     return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
 }
示例#4
0
        public bool RegistrerMal(MalerSkjema mal, string brukernavn)
        {
            var dbtp = new DbTransaksjonerProsjekt();

            if (!dbtp.ErAdmin(brukernavn, mal.ProsjektId) && !dbtp.ErEier(brukernavn, mal.ProsjektId))
            {
                return false;
            }
                     
            var nyMal = new Maler()
            {
                startTid = mal.startTid,
                sluttTid = mal.sluttTid,
                ProsjektId = mal.ProsjektId,
                Tittel = mal.Tittel
            };
          
           using (var db = new Dbkontekst())
            {
                try
                {
                    db.Maler.Add(nyMal);
                    db.SaveChanges();
                    return true;
                }
                catch (Exception feil)
                {
                    return false;
                }

            }

        }
示例#5
0
        public void SettInnMal_OK()
        {
            var _mock = new Mock<InterfaceDbTVakt>();

            MalerSkjema maler = new MalerSkjema()
            {
                ProsjektId = 1,
                startTid = "12:15",
                sluttTid = "13.15"
            };
            var brukernavn = new dbBruker();
            

            _mock.Setup(x => x.RegistrerMal(maler, brukernavn.Email)).Returns(true);
            _mock.Verify(framework => framework.RegistrerMal(maler, brukernavn.Email), Times.AtMostOnce());

            InterfaceDbTVakt lovable = _mock.Object;
            var actual = lovable.RegistrerMal(maler, brukernavn.Email);

            Assert.AreEqual(true, actual);
        }
示例#6
0
 public bool RegistrerMal(MalerSkjema mal, string brukernavn)
 {
     return _repository.RegistrerMal(mal, brukernavn);
 }