public void Should_call_api_search_service_if_barcode_is_new()
        {
            var barcode = new BarCode() { New = true };
            A.CallTo(() => this.barCodes.Get("", "", 0)).Returns(null);
            A.CallTo(() => this.barCodes.Create("", "", 0)).Returns(barcode);
            A.CallTo(() => this.apiSearchService.Search("", "")).Returns(Enumerable.Empty<ApiSearchHit>());

            barCodeController.Get("", "", 0);

            A.CallTo(() => apiSearchService.Search("","")).MustHaveHappened();
        }
        public void Should_be_allowed_to_update_barcode_if_format_and_code_is_the_same()
        {
            var updateBarCode = new BarCode() { Format = "EAN_13", Code = "1234567890", Id = 1, Name="foo", Manufacturer = "bar"};
            var repoBarCode = new BarCode() { Format = "EAN_13", Code = "1234567890", Id = 1 };

            A.CallTo(() => this.barCodes.Get(1, 0)).Returns(repoBarCode);

            barCodeController.Update(updateBarCode, 0);

            A.CallTo(() => this.barCodes.Update(A<BarCode>.That.Matches(x => x.Name == "foo" && x.Manufacturer=="bar"), A<long>._)).MustHaveHappened(Repeated.Exactly.Once);
        }
        public BarCode Update(BarCode barCode, long userId)
        {
            var originalCode = this.barCodes.Get(barCode.Id, userId);
              if (originalCode.Format == barCode.Format && originalCode.Code == barCode.Code)
              {
                  // stuff that we allow to be updated
                  originalCode.Name = barCode.Name;
                  originalCode.Manufacturer = barCode.Manufacturer;

                  this.barCodes.Update(originalCode, userId);
              }
            return originalCode;
        }
 private void Log(BarCode barcode, long userId, string eventName,string data = null)
 {
     this.Log(barcode.Id, userId, eventName, data);
 }
Пример #5
0
        public void Update(BarCode barCode, long updatedBy)
        {
            using (SqlConnection connection = Connection)
            {
                connection.Open();

                connection.Execute("UPDATE BarCodes set Name = @NAME, Manufacturer = @MANUF where Id = @ID", new { ID = barCode.Id, NAME = barCode.Name, MANUF = barCode.Manufacturer });
            }
        }
        public void Should_return_barcode_from_repo()
        {
            var expectedBarcode = new BarCode();

            A.CallTo(() => this.barCodes.Exists(10)).Returns(true);
            A.CallTo(() => this.barCodes.Get(10, 0)).Returns(expectedBarcode);

            var barcode = barCodeController.Rate(10, 5, 0);

            Assert.AreEqual(barcode, expectedBarcode);
        }
        public void Should_pick_first_item_from_search_hits_and_use_to_update_barcode()
        {
            var barcode = new BarCode() { New = true };
            var searchHit = new ApiSearchHit() {Manufacturer = "lol", Name = "baz"};
            A.CallTo(() => this.barCodes.Get("", "", 0)).Returns(null);
            A.CallTo(() => this.barCodes.Create("", "", 0)).Returns(barcode);
            A.CallTo(() => this.apiSearchService.Search("", "")).Returns(new []{searchHit});

            barCodeController.Get("", "", 0);

            A.CallTo(() => this.barCodes.Update(A<BarCode>.That.Matches(x => x.Name=="baz" && x.Manufacturer== "lol"), 0)).MustHaveHappened();
        }
        public void Should_not_update_if_input_barcode_has_the_wrong_format_is_the_same()
        {
            var updateBarCode = new BarCode() {Format = "EAN_13", Id=1};
            var repoBarCode = new BarCode() {Format = "UPC", Id=1};

            A.CallTo(() => this.barCodes.Get(1, 0)).Returns(repoBarCode);

            barCodeController.Update(updateBarCode, 0);

            A.CallTo(() => this.barCodes.Update(A<BarCode>._,A<long>._)).MustNotHaveHappened();
        }
        public void Should_not_update_if_input_barcode_has_the_wrong_code_is_the_same()
        {
            var updateBarCode = new BarCode() { Code = "1234567890", Id = 1 };
            var repoBarCode = new BarCode() { Code = "0987654321", Id = 1 };

            A.CallTo(() => this.barCodes.Get(1, 0)).Returns(repoBarCode);

            barCodeController.Update(updateBarCode, 0);

            A.CallTo(() => this.barCodes.Update(A<BarCode>._, A<long>._)).MustNotHaveHappened();
        }
        public void should_not_to_api_lookup_if_barcode_is_old()
        {
            var barcode = new BarCode() {New = false};
            A.CallTo(() => this.barCodes.Get("", "", 0)).Returns(barcode);

            barCodeController.Get("", "", 0);

            A.CallTo(() => this.apiSearchService.Search("","")).MustNotHaveHappened();
        }