Exemplo n.º 1
0
        private void ShouldReturnSuccessForUpdate()
        {
            var operationSecceded = false;
            var dataAccessJsonStr = string.Empty;
            var formattedJsonStr  = string.Empty;

            try
            {
                var model = new TipeModel()
                {
                    id         = 1,
                    nama       = "Tipe #1 (Update)",
                    keterangan = "Keterangan Tipe #1"
                };

                _services.Update(model);
                operationSecceded = true;
            }
            catch (DataAccessException ex)
            {
                operationSecceded = ex.DataAccessStatusInfo.OperationSucceeded;
                dataAccessJsonStr = JsonConvert.SerializeObject(ex.DataAccessStatusInfo);
                formattedJsonStr  = JToken.Parse(dataAccessJsonStr).ToString();
            }

            try
            {
                Assert.True(operationSecceded);
                _testOutputHelper.WriteLine("Data berhasil diubah.");
            }
            finally
            {
                _testOutputHelper.WriteLine(formattedJsonStr);
            }
        }
Exemplo n.º 2
0
        private void ShouldReturnErrorDuplicateUpdate()
        {
            var dataAccessJsonStr = string.Empty;
            var formattedJsonStr  = string.Empty;

            try
            {
                var model = new TipeModel()
                {
                    id   = 1,
                    nama = "Tipe #2",
                };

                _services.Update(model);
            }
            catch (DataAccessException ex)
            {
                dataAccessJsonStr = JsonConvert.SerializeObject(ex.DataAccessStatusInfo);
                formattedJsonStr  = JToken.Parse(dataAccessJsonStr).ToString();
            }
            finally
            {
                _testOutputHelper.WriteLine(formattedJsonStr);
            }
        }
        public ActionResult Create(TipeModel model)
        {
            try
            {
                Tipe tipe = new Tipe()
                {
                    TipePesawat = model.TipePesawat
                };

                context.Tipes.InsertOnSubmit(tipe);
                context.SubmitChanges();
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(model));
            }
        }
Exemplo n.º 4
0
        public void ShouldReturnModelMatchingId()
        {
            TipeModel model   = null;
            var       idToGet = 1;

            try
            {
                model = (TipeModel)_services.GetById(idToGet);
            }
            catch (DataAccessException ex)
            {
                _testOutputHelper.WriteLine(ex.DataAccessStatusInfo.GetFormatedValues());
            }

            Assert.True(model != null);
            Assert.True(model.id == idToGet);

            if (model != null)
            {
                TestsHelper.WriteModel(_testOutputHelper, model);
            }
        }
Exemplo n.º 5
0
        private void ShouldReturnSuccessForInsert()
        {
            var operationSecceded = false;
            var dataAccessJsonStr = string.Empty;
            var formattedJsonStr  = string.Empty;

            try
            {
                for (int i = 1; i <= 10; i++)
                {
                    var model = new TipeModel()
                    {
                        nama       = $"Tipe #{i}",
                        keterangan = $"Keterangan Tipe #{i}"
                    };

                    _services.Insert(model);
                }

                operationSecceded = true;
            }
            catch (DataAccessException ex)
            {
                operationSecceded = ex.DataAccessStatusInfo.OperationSucceeded;
                dataAccessJsonStr = JsonConvert.SerializeObject(ex.DataAccessStatusInfo);
                formattedJsonStr  = JToken.Parse(dataAccessJsonStr).ToString();
            }

            try
            {
                Assert.True(operationSecceded);
                _testOutputHelper.WriteLine("Data berhasil ditambahkan.");
            }
            finally
            {
                _testOutputHelper.WriteLine(formattedJsonStr);
            }
        }
Exemplo n.º 6
0
        private void OperationButtons_OnSaveButtonClick(object sender, EventArgs e)
        {
            var model = new TipeModel
            {
                nama       = textBoxNama.Text,
                keterangan = textBoxKeterangan.Text
            };

            var modelArgs = new ModelEventArgs <TipeModel>(model);

            if (_isNewData)
            {
                if (Messages.ConfirmSave(_typeName))
                {
                    OnSaveData?.Invoke(this, modelArgs);
                }
            }
            else if (Messages.ConfirmUpdate(_typeName))
            {
                model.id = _model.id;
                OnSaveData?.Invoke(this, modelArgs);
            }
        }
Exemplo n.º 7
0
 public TipeServicesFixture()
 {
     Model    = new TipeModel();
     Services = new TipeServices(null, new ModelDataAnnotationCheck());
 }